I am working on a website with a form that is used to send email with PHPMailer. i have a GoDaddy hosting plan linux. I have tried multiple ways without any success, some time ago it worked and now does not work.
Configuration 1 with Gmail
include_once('phpmailer/class.phpmailer.php');
include_once('phpmailer/class.smtp.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = false;
$mail->SMTPSecure = false; (I've tried the 2 options)
$mail->Host = "relay-hosting.secureserver.net";
$mail->Port = 25;
$mail->Username ='xxxx#gmail.com';
$mail->Password = 'xxxxxxx';
$mail->Subject = 'Form from website';
$mail->AddAddress("xxxxx#xxxx.com");
$mail->FromName = "formsite";
$mail->SMTPDebug = 3;
$mail->Debugoutput = 'html';
Log
Connection: opening to relay-hosting.secureserver.net:25, timeout=300, options=array ()
SMTP ERROR: Failed to connect to server: Connection refused (111)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Configuration 2 email from the same domain
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPSecure = true; // Enable TLS encryption, `ssl` also accepted
$mail->SMTPAuth = false; // Enable SMTP authentication
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Host = 'p3plcpnxxx.prod.phx3.secureserver.net';
$mail->Port = 465;
$mail->Username ='noreply#samedomain.com';
$mail->Password = 'xxxxxxxx';
$mail->Subject = 'Form from website';
$mail->AddAddress("xxxxx#xxxx.com");
$mail->FromName = "formsite";
$mail->SMTPDebug = 3;
$mail->Debugoutput = 'html';
Log
SERVER -> CLIENT: 220-p3plcpnxxxx.prod.phx3.secureserver.net ESMTP Exim 4.89 #1 Thu, 14 Dec 2017 21:11:11 -0700 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
CLIENT -> SERVER: EHLO www.xxxxxx.com
SERVER -> CLIENT: 250-p3plcpnxxxx.prod.phx3.secureserver.net Hello
p3plcpnxxxx.prod.phx3.secureserver.net [180.168.200.196]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250-CHUNKING250 HELP
To help others struggling with GoDaddy, these two variations worked for me:
Hosting: GoDaddy shared/cPanel
Sending "From:" a GMail address
PHPMailer version 6.0.5
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$send_using_config = 1; // set to 1, 2, etc. to test different settings
switch ($send_using_config):
case 1:
$mail->Host = 'localhost';
$mail->Port = 25;
$mail->SMTPSecure = FALSE;
$mail->SMTPAuth = FALSE;
$mail->SMTPAutoTLS = FALSE;
break;
case 2:
# Host amnd Port info obtained from:
# Godaddy > cPanel Home > Email > cPanel Email > Mail Configuration > "Secure SSL/TLS Settings" > Outgoing Server
$mail->Host = 'a2plcpnxyzw.prod.iad2.secureserver.net';
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = FALSE;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => FALSE,
'verify_peer_name' => FALSE,
'allow_self_signed' => TRUE
)
);
break;
endswitch;
$mail->Username = 'you#gmail.com';
$mail->Password = 'your_gmail_password';
$mail->setFrom($from);
$mail->addAddress($to);
$mail->Subject = $subject;
$mail->msgHTML($message);
$mail->send();
These settings are based on the question posted here and modified with the advice from #Synchro on StackOverflow and GitHub. Thank you #Synchro!
Related
I am having an issue using PHPmailer class in laravel ,sometimes the email is sent and in very rare case its not sent but after the $mail->send() function all the other script is running fine and it doesn't even throw any error and I am unable to find out whats wrong. below is my code.
$to_email = '';
$from_email = 'banca#jubileegeneral.com.pk';
$mail = new PHPMailer();
try {
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
//Server settings
$mail->SMTPDebug = 1; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.something.com.pk'; // Set the SMTP server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'something#gmail.com'; // SMTP username
$mail->Password = 'xyz'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 25; // TCP port to connect to
//Recipients
$mail->setFrom($from_email, 'TESTING');
$mail->addAddress(Auth::user()->email);
$mail->addBCC('something#abc.com.pk');
$mail->isHTML(true);
$mail->Subject = 'XYZ ';
$mail->Body = 'Hey';
$mail->AltBody = '';
$mail->send();
I need help please
this is my code:
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->Username = 'some#gmail.com';
$mail->Password = 'somepass';
$mail->addAddress('another#gmail.com', 'Josh Adams');
$mail->Subject = 'PHPMailer GMail SMTP test';
$body = 'This is the HTML message body in bold!';
$mail->MsgHTML($body);
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
and I get this error:
2013-12-11 15:15:02 SMTP ERROR: Failed to connect to server: Network is unreachable (101) SMTP connect() failed. Mailer Error: SMTP connect() failed.
any help please?
You might want to start by isolating this problem to determine whether it's truly a network problem; or whether it's specific to PHP mailer or your code. On your server, from a command prompt, try using telnet to connect to smtp.gmail.com on port 587, like so:
telnet smtp.gmail.com 587
You should see a response from smtp.gmail.com, like so:
Trying 173.194.74.108...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP f19sm71757226qaq.12 - gsmtp
Do you see this, or does the connection attempt hang and eventually time out? If the connection fails, it could mean that your hosting company is blocking outgoing SMTP connections on port 587.
This worked for me:
change:
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = '465';
to
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = '587';
The code below:
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Host = 'ssl://smtp.gmail.com:465';
I was facing the same issues on Godaddy hosting so I spend lots of time and fix it by disabling the SMTP restriction on the server end.
SMTP code is for PHPMailer
$mail = new PHPMailer(true);
try {
//Server settings
//$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->SMTPDebug = 2; //Enable verbose debug output
//$mail->isSMTP(); //Send using SMTP
$mail->Host = "tls://smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = contact#example.in;
$mail->Password = SMTP_PASSWORD;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
//Recipients
$mail->setFrom('contact#example.in', 'Online Order');
$mail->addAddress('test#gmail.com'); //Add a recipient
$mail->addReplyTo('contact#example.in', 'Jewellery');
//Attachments
//$mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Order';
$mail->Body = 'This is test email content';
$mail->AltBody = 'This is test email content';
if($mail->send()){
return '1';
}else{
return 'Order email sending failed';
}
change
$mail->SMTPSecure = "tls";
with
$mail->SMTPSecure = 'ssl';
On sending emails from Gmail through SMTP I got this error:
SMTP Error: Could not connect to SMTP host
I tried:
require_once('mailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->AddAddress($email);
$mail->Username="mail#gmail.com";
$mail->Password="password";
$mail->SetFrom('mail#gmail.com','Store');
$mail->AddReplyTo("mail#gmail.com","Store");
$mail->Subject = $subject;
$mail->MsgHTML($message);
$mail->Send();
Gmail account setting for "Less secure apps" is turned on
Update:
After trying this answer, I am getting:
Fatal error: Class 'SMTP' not found in C:\wamp64\www\project\mailer\class.phpmailer.php on line 1522
I am using below code for setting my values.. and it is working fine for me.
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = "smtp.gmail.com";
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = "mail#gmail.com";
//Password to use for SMTP authentication
$mail->Password = "password";
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->setFrom("mail#gmail.com",$from);
$mail->addAddress("mail#gmail.com");
//Set the subject line
$mail->Subject = "subject";
$mail->Body = "body";
$mail->send();
I want to send mail as outlook mail... but it shows the connection error and authentication error if some port numbers are changed... what wrong in my code....
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->CharSet = 'UTF-8';
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "outlook.office365.com";
$mail->Port = 993;
$mail->Username = "harish.reddy#skoopview.com";
$mail->Password = "XXXXXXX";
$mail->From = $from;
$mail->FromName= $FromName;
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->addAddress('harish.reddy#skoopview.com','harish');
if(!$mail->send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
echo "E-Mail has been sent";
}
It shows error like this ... What i do ??
SERVER -> CLIENT: * OK The Microsoft Exchange IMAP4 service is ready.
[SABLAE4AUABSADAANgBDAEEAMAAwADUAMwAuAGEAcABjAHAAcgBkADAANgAuAHAAcgBvAGQALgBvAHUAdABsAG8AbwBrAC4AYwBvAG0A]
* BYE Connection is closed. 13 2016-09-12 10:50:13 SMTP NOTICE: EOF caught while checking if connected 2016-09-12 10:50:13 SMTP Error:
Could not authenticate. 2016-09-12 10:50:13 SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer
Error: SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Thankyou....,
As George stated, the port should be 587. Make sure you are using TLS:
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp-mail.outlook.com;smtp.office365.com'; // Specify main and backup SMTP servers
But Outlook self-signs its own SSL/TLS certificate. Hence you need to add this piece of code as per https://github.com/PHPMailer/PHPMailer/issues/914:
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
I would try port 587 for SMTP - more details here: https://support.office.com/en-gb/article/POP-and-IMAP-settings-for-Outlook-Office-365-for-business-7fc677eb-2491-4cbc-8153-8e7113525f6c
Have a basic contact form using https://github.com/PHPMailer/PHPMailer on a Network Solutions shared hosting package.
// start the mail request basics
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->Debugoutput = 'html';
$mail->SMTPAuth = true; // authentication enabled
$mail->Host = 'ssl://smtp.gmail.com';
$mail->Port = 587;
$mail->IsHTML(true);
$mail->Username = 'my_gmail_account#gmail.com';
$mail->Password = '*******';
Everything works find locally (on my computer) and form sends email, but when I upload this php file to our network solutions hosting I get the following Error.
SMTP ERROR: Failed to connect to server: Connection timed out (110)
SMTP connect() failed.
Is there something wrong with my Mail Settings? Anyone else had success with PHP mailing on Network Solutions Shared Hosting?
Network Solutions blocks several ports required to send mail including those needed for gmail.
If anyone finds an alternate, please let me know.
For now, used a dummy account and used standard PHP mailer then forwarded mail.
You could change your config options like this.
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->IsHTML(true);
$mail->Username = "my_gmail_account#gmail.com";
$mail->Password = "********";
$mail->SetFrom("somemail#gmail.com");
$mail->Subject = "Testing the New Config";
$mail->Body = "Hey there !";
I got it to work with these settings:
$mail->SMTPOptions = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
"allow_self_signed" => true
)
);
$mail->SMTPAuth = false;
$mail->SMTPSecure = false;
$mail->Host = "email-out-priv.myregisteredsite.com";
$mail->Port = 25;
$mail->Username = "noreply#mydomain.com";
$mail->Password = "********";
You have to pay for an email address with Network Solutions for a domain you own. You can see the host and port by logging into your mailbox (mail.mydomain.com) --> Top right Menu --> Settings --> Mail --> Mail and Social Accounts --> E-Mail (Edit) --> Outgoing server (SMTP). I used this PHP Mailer Documentation as a clue to this solution.