问题
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';
}
回答1:
Some servers have certain functions disable that a user cannot enable them selves. Check with your hosting provider to see if they have the mail() function enabled.
In this case smtp mail function perfectly working in localhost but not in server.. soo you change the server setting
回答2:
That link to the troubleshooting guide is there for a reason - if you follow it it will tell you exactly what is wrong: GoDaddy blocks outbound SMTP, so you have to use their mail servers. There are many duplicates of this question, so search before you post.
来源:https://stackoverflow.com/questions/36786048/why-php-is-sending-email-from-localhost-not-from-server-using-phpmailer