2010-02-09 71 views
9

我试图使用php邮件程序,但错误如下。PHP邮件程序错误

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 = "[email protected]"; 
     $mail->Password = "xxxxxxxx"; 
     $mail->From = "[email protected]"; 
     $mail->FromName = "Mailer"; 
     $mail->AddAddress("[email protected]", "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"; 

     ?> 
+0

你需要一个安全的连接,是不是? – 2010-02-09 09:46:30

回答

14

有些服务器(尤其是共享主机)将阻止你使用SSL SMTP与我有同样的问题一次。

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

喜欢的东西AuthSMTP将是一个备用邮件服务器你最好的选择。

+0

我尝试使用PHp邮件功能,但也没有发送邮件。 – user2480288 2014-04-24 20:37:56

1

不知道,但尝试$mail->Host = "smtp.gmail.com" =>$mail->Host = "smtp.google.com"

+2

smtp.gmail.com是正确的。 – Shoban 2010-02-09 08:39:42

+0

哦,我很抱歉:) – Young 2010-02-09 08:40:46

2

可能是因为防火墙的?

如果您无法登录到谷歌对话, 或者你接收 说,一个错误,无法验证 服务器,检查您是否已经安装了个人 防火墙软件,或者如果您 计算机位于需要用户名和密码的代理服务器 后面。

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

+0

谈话不是邮件,不是吗? – hakre 2013-08-12 07:31:32

5

如果您在本地主机的工作只是去PHP Extention并启用或检查php_openssl 这将是能够访问SSL端口。

8

我有同样的问题,我们似乎有 设置SMPTSecure值。 首先我改变了从端口465至587,并加入:
$ MAIL-> SMTPSecure = “TLS”; 它工作:)

2

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

这些尝试和在PHPMailer的测试设置: $ MAIL-> SMTPSecure = “TLS”; //设置前缀给服务器 $ mail-> Host =“smtp.gmail.com”; //将GMAIL设置为SMTP服务器 $ mail-> Port = 587;

'但是'谷歌将这些服务作为一种'反垃圾邮件'/政治手段予以阻止,这让我感到困惑,因为它可以在本地和大多数托管服务提供商工作,当他们不接受来自主机DNS/IP的出站邮件。接受它并继续寻找另一台smtp服务器来传递消息。

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 = "[email protected]"; 

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

    $mail->setFrom('[email protected]', 'development'); //add sender email address. 

    $mail->addAddress('[email protected]', "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!"; 
    } 
+0

$ mail-> SMTPSecure ='ssl';对我有所帮助,谢谢! – 2015-01-30 07:56:38

+0

@ Cyrille Armanger接受答案,如果它的工作:)提前致谢 – Priyank 2015-01-30 08:00:36

+0

我不是原来的海报,它只是帮助了我。 – 2015-01-30 08:05:35

2

有同样的问题,更改端口号在Opencart的邮件设置为587和工作正常

+0

这对我有效。 – herrmartell 2016-05-12 16:05:57