10

我尝试使用 php mailer,但错误如下。

SMTP -> FROM SERVER:
SMTP -> FROM SERVER:
SMTP -> ERROR: EHLO not accepted from server:
SMTP -> FROM SERVER:
SMTP -> ERROR: HELO not accepted from server:
SMTP -> ERROR: AUTH not accepted from server:
SMTP -> NOTICE: EOF caught while checking if connectedSMTP Error: Could not authenticate. Message could not be sent.

Mailer Error: SMTP Error: Could not authenticate. 

和我的代码

 <?php
        require("class.phpmailer.php")
        $mail = new PHPMailer();        
        $mail->IsSMTP();                                    
        $mail->Host = "smtp.gmail.com";  
        $mail->Port = 465;        
        $mail->SMTPAuth = true;     

        $mail->SMTPDebug = 2;  
        $mail->Username = "admin@xxxxxxxxxxxx.in";  
        $mail->Password = "xxxxxxxx";   
        $mail->From = "admin@xxxxxxxxxxxx.in";
        $mail->FromName = "Mailer";
        $mail->AddAddress("xxxx@yahoo.co.in", "mine");               
        $mail->WordWrap = 50;                                 
        $mail->IsHTML(true);                                  

        $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. <p>";
           echo "Mailer Error: " . $mail->ErrorInfo;
           exit;
        }
        echo "Message has been sent";

        ?>
4

9 回答 9

21

由于 SSL 的端口错误,我得到了这个。

SSL = 465 TLS = 587

请参阅:http: //mail.google.com/support/bin/answer.py ?hl=en&answer=13287

于 2011-09-18T22:03:55.623 回答
14

某些服务器(尤其是共享主机)会阻止您将 SSL 与 SMTP 一起使用,我曾经遇到过同样的问题。

如果可以,请更改主机,尝试使用默认的 PHP mail() 函数或通过另一个不需要 SSL 的邮件服务器发送,例如端口 25 而不是 465。

对于备用邮件服务器,像AuthSMTP这样的东西将是您的最佳选择。

于 2010-02-09T09:42:29.177 回答
9

我遇到了同样的问题,看来我们必须设置 SMPTSecure 值。首先,我将端口从 465 更改为 587 并添加:
$mail->SMTPSecure = "tls"; 它奏效了:)

于 2013-03-20T12:55:46.253 回答
5

如果您在本地主机中工作,只需转到PHP 扩展并启用或检查php_openssl 它将能够访问 SSL 端口。

于 2012-08-30T05:58:54.613 回答
3

try this code

require '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 = 2;

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

    //Set the hostname of the mail server
    $mail->Host = 'smtp.gmail.com';

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

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

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

    //Username to use for SMTP authentication - use full email address for gmail
    $mail->Username = "admin@gmail.com";

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

    $mail->setFrom('admin3@gmail.com', 'development');  //add sender email address.

    $mail->addAddress('admins@gmail.com', "development");  //Set who the message is to be sent to.
    //Set the subject line
    $mail->Subject = $response->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->Body     = 'Name: '.$data['name'].'<br />Location: '.$data['location'].'<br />Email: '.$data['email'].'<br />Phone:'.$data['phone'].'<br />ailment: '.$data['ailment'].'<br />symptoms: '.$data['symptoms'];

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

    //Attach an image file
    //$mail->addAttachment('images/phpmailer_mini.gif');
    //$mail->SMTPAuth = true;
    //send the message, check for errors
    if (!$mail->send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message sent!";
    }
于 2014-09-08T12:31:12.680 回答
3

有同样的问题,将opencart邮件设置中的端口号更改为587并且工作正常

于 2015-11-06T06:36:36.133 回答
2

可能是因为防火墙?

如果您无法登录 Google Talk,或者您收到一条错误消息,提示您无法对服务器进行身份验证,请检查您是否安装了个人防火墙软件,或者您的计算机是否位于需要用户名和密码。

http://www.google.com/support/talk/bin/answer.py?hl=en&answer=30998

于 2010-02-09T08:41:27.253 回答
2

我对多个客户端使用相同的脚本,并且仅在部署到 Amazon EC2 云提供商(例如 Openshift)时遇到此问题。

这些是 phpmailer 中经过试验和测试的设置: $mail->SMTPSecure = "tls"; // 设置服务器前缀 $mail->Host = "smtp.gmail.com"; // 将 GMAIL 设置为 SMTP 服务器 $mail->Port = 587;

“但是”谷歌将这些服务作为一种“反垃圾邮件”/政治策略来阻止,这让我感到震惊,因为它在本地和大多数托管服务提供商上都有效,当他们不接受来自的出站消息时,你无能为力您的主机 DNS / IP。接受它并继续寻找另一个 smtp 服务器来路由消息。

于 2014-04-09T06:39:02.703 回答
1

不确定但试试$mail->Host = "smtp.gmail.com" =>$mail->Host = "smtp.google.com"

于 2010-02-09T08:36:40.090 回答