我使用SMTPMail发送邮件。首先,我只是从我的本地主机进行测试,并且它已成功发送电子邮件。为什么php使用PHPMailer从本地主机发送邮件而不是从服务器发送邮件?
但是,当我将相同的代码上传到我的服务中时,它显示我没有发送电子邮件的错误,
错误信息是:
2016年4月22日5点53分10秒SMTP错误:无法连接到服务器:连接被拒绝(111)2016年4月22日5点53分10秒SMTP连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting邮件不发送
我不明白为什么它显示我这个错误信息,因为我使用100%相同的代码。
下面是使用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 = '[email protected]';
$m->FromName = 'Shibbir Ahmed';
$m->addReplyTo('[email protected]', 'Reply Address');
$m->addAddress('[email protected]', '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';
}
[GoDaddy Linux共享尝试通过GMAIL SMTP发送PHP的可能的副本](http://stackoverflow.com/questions/5440026/php-on-godaddy-linux-shared-trying-to-send-through- gmail-smtp) – Synchro