I search google and this site and can't fix this phpMailer error and that's why I need you help.
I am sending email using following phpMailer code but all time it's showing me error message :
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
PhpMailer Code
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = gethostbyname("smtp.gmail.com");
$mail->SMTPAuth = true;
$mail->Username = 'hello@gmail.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->isHTML(true);
$mail->Priority = 1;
$to = 'to@gmail.com';
$mail->setFrom('support@site.com', 'Sitename');
// Send Email tto user ####################################
$mail->addAddress('some@gmail.com', 'Shibbir Ahmed');
// send email to admin #####################################
$mail->addReplyTo('some@gmail.com', 'Information');
$mail->Subject = 'Test Subject';
$get_templae = mysqli_query($conn, "SELECT * FROM email_template WHERE t_id = '8' ");
$get_restult = mysqli_fetch_array($get_templae);
$template = $get_restult['t_content'];
$mail->Body = $template;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
Can you please tell what I am doing wrong in this code ?
I am getting this error :
2016-04-21 15:19:51 SMTP ERROR: Failed to connect to server: Connection refused (111) 2016-04-21 15:19:51 SMTP connect() failed. github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Update :
Current Error from my server :
2016-04-21 18:06:01 SMTP ERROR: Failed to connect to server: Connection refused (111) 2016-04-21 18:06:01 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting bool(false)
Try to lower your gmail security, for the SMTP!
Link: https://www.google.com/settings/security/lesssecureapps
And add de debuginfo property to see more what is wrong.
$mail->SMTPDebug = 1;
you can change the value to 1 2 3 or 4 to ingress the filtering form debuginfo.
Hope this helps you out ;)
The best ways to debug PHPMailer errors is to uncomment
$mail->SMTPDebug = 3;
It will give you a detailed log of the events happening. From authentication all the way to where the request is successful or fails
Step1: Go to Gmail setting and enable IMAP. Step2: Clear your browser cache and check it.
If issue still persists lower your Gmail security by using "settings" tab. Gmail Security alert will be like this
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.