PHP邮件发送错误

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";

        ?>

你需要一个安全连接,不是吗? - Horia Dragomir
9个回答

21

这个答案……经过多次故障排除,这才是最终适用于我的。非常感谢您。 - Joel

14

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

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

类似AuthSMTP这样的备用邮件服务器可能是您的最佳选择。


我尝试使用PHP邮件函数,但是邮件也没有被发送。 - user2480288

9

我遇到了同样的问题,看起来我们需要设置SMPTSecure值。 首先,我将端口从465更改为587,并添加:
$mail->SMTPSecure = "tls"; 然后它就可以工作了 :)


5
如果您正在本地主机上工作,只需进入 PHP 扩展 并启用或检查 php_openssl,它就可以访问 SSL 端口了。

3

试试这个代码

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!";
    }

$mail->SMTPSecure = 'ssl'; 对我很有帮助,谢谢! - Cyrille Armanger
@ Cyrille Armanger如果答案有效请接受它 :) 预先感谢您 - Priyank
我不是原帖作者,只是它对我有所帮助。 - Cyrille Armanger

3

我遇到了同样的问题,在opencart邮件设置中更改端口号为587,问题得以解决。


2

说话不等于发邮件,是吧? - hakre

2

我在为多个客户使用相同的脚本,在部署到亚马逊 EC2 云服务提供商(如 Openshift)时才遇到这个问题。

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

但是,由于谷歌将这些服务作为“反垃圾邮件”/政治策略而屏蔽了它们,因此当它在本地和大多数托管提供商上运行时,这让我感到困惑。当他们不接受从您的主机 DNS / IP 发送的出站消息时,您无法做太多事情。接受它并寻找另一个 SMTP 服务器来路由消息。


1

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接