I am using PHPMailer with SMTP to send email. First I just test it from my localhost and it's successfully sent email.
But when I upload the same code to my service it's showing me following error without sending email;
Error Message is :
2016-04-22 05:53:10 SMTP ERROR: Failed to connect to server: Connection refused (111) 2016-04-22 05:53:10 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting mail is not send
I do not understand why it's showing me this error message becuase I am using 100% same code.
Here is my email sending script using PHPMailer :
require 'PHPMailerAutoload.php';
$m = new PHPMailer();
$m->isSMTP();
$m->SMTPAuth = true;
$m->SMTPDebug = 2;
$m->Host = 'smtp.gmail.com';
$m->Username = 'username';
$m->Password = 'password'; // google app password
$m->SMTPSecure = 'ssl';
$m->Port = 465;
$m->From = 'from@gmail.com';
$m->FromName = 'Shibbir Ahmed';
$m->addReplyTo('reply@gmail.com', 'Reply Address');
$m->addAddress('to@gmail.com', 'Shibbir Ahmed');
$m->Subject = 'Here is an email';
$m->Body = 'This is email';
$m->AltBody = 'Alt body';
if($m->send()) {
echo 'mail send';
} else {
echo 'mail is not send';
}