PHPMailer SMTP连接错误()失败

时间:2014-07-16 13:26:55

标签: phpmailer

我使用https://github.com/PHPMailer/PHPMailer中的PHPMailer并使用以下代码:

<?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';
$mail->port = '25';
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'xxx@gmail.com';                 // SMTP username
$mail->Password = 'xxx';                           // SMTP password

$mail->From = 'xxx@gmail.com';
$mail->FromName = 'xxx';
$mail->addAddress('xxx@xxx.com', 'xxx');     // Add a recipient



$mail->WordWrap = 50;                                 // Set word wrap to 50 characters

$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

当我运行它时,它会出错:

Message could not be sent.Mailer Error: SMTP connect() failed.

但是当我在localhost(windows和xampp)上运行它时它会成功!

0 个答案:

没有答案