无法从家庭服务器发送电子邮件

时间:2015-08-22 11:42:26

标签: php gmail debian virtual-machine phpmailer

我最近决定将我的网站从godaddy.com移到我的家庭服务器......事情变得非常顺利,除了我还没有能够发送任何电子邮件!我正在运行安装了最新Debian的VM。主机正在运行Windows Server 2012 R2 Standard。以下列出了我已经尝试过的事情:

  • 禁用所有防火墙(VM,主机,路由器)
  • 尝试过不同的电子邮件程序:sendmail,exim等

我可以看到队列中的消息,但它们会一直存在,直到我收到超时消息。

这是我设置的testmail页面的代码:

    <?php
/**
 * This example shows settings to use when sending via Google's Gmail servers.
 */

//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('America/New_York');

require 'PHPMailer/PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;

//Tell PHPMailer to use SMTP
$mail->isSMTP();

//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 4;

//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';

//Set the hostname of the mail server

$mail->Host = gethostbyname('smtp.gmail.com');
// use
// $mail->Host = gethostbyname('smtp.gmail.com'); was: $mail->Host = 'smtp.gmail.com';
// if your network does not support SMTP over IPv6

//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;

//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';

//Whether to use SMTP authentication
$mail->SMTPAuth = true;

//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "correct_username";

//Password to use for SMTP authentication
$mail->Password = "correct_password";

//Set who the message is to be sent from
$mail->setFrom('admin@homeworth123.com', 'Homeworth 1 2 3');

//Set an alternative reply-to address
$mail->addReplyTo('michael@or515.com', 'Michael Rosenbaum');

//Set who the message is to be sent to
$mail->addAddress('drknowitall@outlook.com', 'Mikey Router');

//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';

//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(file_get_contents('PHPMailer/examples/contents.html'), dirname(__FILE__));

//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';

//Attach an image file
$mail->addAttachment('PHPMailer/examples/images/phpmailer_mini.png');

//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}
?>

这是我运行时的结果:

Connection: opening to 74.125.25.108:587, timeout=300, options=array ()
Connection: opened
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "220 smtp.gmail.com ESMTP ng13sm4536549pdb.21 - gsmtp"
SERVER -> CLIENT: 220 smtp.gmail.com ESMTP ng13sm4536549pdb.21 - gsmtp
CLIENT -> SERVER: EHLO homeworth123.com
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "250-smtp.gmail.com at your service, [My IP shows here]"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [My IP shows here]"
SMTP -> get_lines(): $str is "250-SIZE 35882577"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [My IP shows here]250-SIZE 35882577"
SMTP -> get_lines(): $str is "250-8BITMIME"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [My IP shows here]250-SIZE 35882577250-8BITMIME"
SMTP -> get_lines(): $str is "250-STARTTLS"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [My IP shows here]250-SIZE 35882577250-8BITMIME250-STARTTLS"
SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [My IP shows here]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES"
SMTP -> get_lines(): $str is "250-PIPELINING"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [My IP shows here]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING"
SMTP -> get_lines(): $str is "250-CHUNKING"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [My IP shows here]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING"
SMTP -> get_lines(): $str is "250 SMTPUTF8"
SERVER -> CLIENT: 250-smtp.gmail.com at your service, [My IP shows here]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
CLIENT -> SERVER: STARTTLS
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "220 2.0.0 Ready to start TLS"
SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
CLIENT -> SERVER: QUIT
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is ""
SERVER -> CLIENT: 
SMTP ERROR: QUIT command failed: 
Connection: closed
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

寻找有关其他事情的建议。谢谢。

0 个答案:

没有答案