SMTP错误:无法连接到SMTP主机

时间:2011-06-01 23:59:33

标签: php smtp phpmailer

我有这个代码,一切都在我的本地服务器上运行良好。电子邮件发送没有任何问题。

但现在我将内容传递给了网络服务器,我收到了这个错误......

SMTP Error: Could not connect to SMTP host.

SSL在服务器中启用..正确吗?那么,问题是什么? enter image description here

            $mail = new PHPMailer();
            $mail->IsSMTP();
            $mail->SMTPAuth   = true;                  // enable SMTP authentication
            $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
            $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
            $mail->Port       = 465;                   // set the SMTP port
            $mail->Username   = "dnteiro"; // GMAIL username
            $mail->Password   = "xxx";      // GMAIL password

3 个答案:

答案 0 :(得分:8)

听起来您的网络主机阻止了与smtp.gmail.com:465的出站连接。建议:

  1. 验证:如果您拥有对您的网络托管服务器的shell /终端访问权限,请尝试使用telnet测试来验证它们实际上阻止了此。运行telnet smtp.gmail.com 465

  2. 联系人:致电或发送电子邮件给您的托管服务提供商,了解他们为出站转发提供的SMTP服务器。确保他们知道您要将@gmail.com地址用作发件人/回复地址。

  3. 更新代码:主机为您提供不同的邮件服务器后,请更新您的代码并重试。

  4. 如果您的Web主机根本不允许从其服务器进行出站中继,那么您需要查看交换主机,如果这是您的应用程序的要求。

答案 1 :(得分:0)

AJ对于#2是正确的,它在以下内容中指定: http://support.google.com/mail/bin/answer.py?hl=en&answer=78775

答案 2 :(得分:0)

require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'mail.abc.co.in';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->SMTPOptions = array(
    'ssl' => array(
    'verify_peer' => false,
    'verify_peer_name' => false,
    'allow_self_signed' => true
    )
); 

$mail->Username = 'user name';
$mail->Password = 'password';

$mail->setFrom("from email id", "name");
$mail->addAddress("receipiant email id");

$mail->isHTML(true);
$bodycontent = 'body';
$mail->Body    = $bodycontent;

if (!$mail->send()) {
    echo "message has been not send", $mail->ErrorInfo;
    }
else{
    echo "message has been send";
    }
相关问题