PHPMailer通过本地而不是远程SMTP(GMAIL)发送

时间:2015-05-15 17:45:43

标签: php amazon-ec2 smtp gmail phpmailer

所以我在EC2服务器上安装了cPanel。 但是要使用PHP发送电子邮件,我使用的是PHPMailer:

$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 587;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
$mail->SMTPDebug = 3;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Username to use for SMTP authentication
$mail->Username = 'email@mysite.com';
//Password to use for SMTP authentication
$mail->Password = 'mypass';
//Set who the message is to be sent from
$mail->setFrom('from@mysite.com', 'My Site');
//Set who the message is to be sent to
$mail->addAddress('email@othersite.com');
// Set charset
$mail->CharSet = 'utf-8';
//Set the subject line
$mail->Subject = 'Subject';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML('my Message');

//send the message, check for errors
echo $mail->send();

PHPMailer调试输出是:

SMTP -> FROM SERVER:220-myserver.com ESMTP Exim 4.85 #2 Fri, 15 May 2015 14:34:35 -0300 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail. 
SMTP -> FROM SERVER: 250-myserver.com Hello ip-123-45-67-89.sa-east-1.compute.internal [123.45.67.89] 250-SIZE 52428800 250-8BITMIME 250-PIPELINING 250-AUTH PLAIN LOGIN 250-STARTTLS 250 HELP 
SMTP -> FROM SERVER:220 TLS go ahead 
SMTP -> FROM SERVER: 250-myserver.com Hello ip-123-45-67-89.sa-east-1.compute.internal [123.45.67.89] 250-SIZE 52428800 250-8BITMIME 250-PIPELINING 250-AUTH PLAIN LOGIN 250 HELP 
SMTP -> FROM SERVER:250 OK 
SMTP -> FROM SERVER:250 Accepted 
SMTP -> FROM SERVER:354 Enter message, ending with "." on a line by itself 
SMTP -> FROM SERVER:250 OK id=1YtJVN-0007Lr-Us 
SMTP -> FROM SERVER:221 myserver.com closing connection 
1

PHPMailer应使用Gmail SMTP服务器发送电子邮件,而是使用本地SMTP服务器。

我正在使用gmail通知我的服务器上已注册的客户端,但DNS尚未设置为我的服务器。

我在没有cpanel和SMTP服务器的其他服务器上尝试了完全相同的代码,并且它在gmail响应中运行良好。

SMTP -> FROM SERVER:220 mx.google.com ESMTP 72sm1238383qhx.32 - gsmtp 
SMTP -> FROM SERVER: 250-mx.google.com at your service, [123.45.67.89] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 
SMTP -> FROM SERVER:220 2.0.0 Ready to start TLS 
SMTP -> FROM SERVER: 250-mx.google.com at your service, [123.45.67.89] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 
SMTP -> FROM SERVER:250 2.1.0 OK 72sm1238383qhx.32 - gsmtp 
SMTP -> FROM SERVER:250 2.1.5 OK 72sm1238383qhx.32 - gsmtp 
SMTP -> FROM SERVER:354 Go ahead 72sm1238383qhx.32 - gsmtp 
SMTP -> FROM SERVER:250 2.0.0 OK 1431704928 72sm1238383qhx.32 - gsmtp 
SMTP -> FROM SERVER:221 2.0.0 closing connection 72sm1238383qhx.32 - gsmtp

有人可以帮助我吗?

0 个答案:

没有答案