druybew06513 2014-04-27 18:13
浏览 40
已采纳

发送邮件时,php connect()在php中失败错误

I am trying to send mail to user when form is submitted. I have the same code in my local host and my server which is aws both running on ubuntu. On my local host I get SMTP connect() failed while it is working fine in my server indicating that the php/smtp settings on my local computer are configured wrong but I can't figure what. Following is the dump of error I got on my local computer.

2014-04-27 18:04:40 CLIENT -> SERVER: EHLO localhost 2014-04-27 18:04:41    
SMTP ERROR: EHLO command failed: 220 mx.google.com ESMTP yv5sm29656409pbb.49 - gsmtp 2014-04-27 18:04:41    CLIENT -> SERVER: HELO localhost 2014-04-27 18:04:41    
SMTP ERROR: HELO command failed: 552 Command sent before response recieved. 2014-04-27 18:04:41 CLIENT -> SERVER: STARTTLS 2014-04-27 18:04:41  
SMTP ERROR: STARTTLS command failed: 2014-04-27 18:04:41    
SMTP NOTICE: EOF caught while checking if connected 
SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.

Following is my html code

<html>

<body>

<section class="stats" id="signup">
<div class="container" >


    <form action="index.php" method="post"  class="subscription wow fadeInLeft animated" data-wow-offset="30" data-wow-duration="1.5s" data-wow-delay="0.15s" role="form">
        <input type="email" placeholder="Enter email" class="form-control input-box" name="email_address">
        <button class="btn btn-primary custom-button red-btn">Sign Up</button>
    </form>


</div> 
</section> 



<?php



if(!isset($_POST['email_address']) || trim($_POST['email_address']) == '')
{

} else {

require '/usr/share/php5/PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer;
$mail->SMTPDebug = 1;
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';  // Specify main and backup server
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'team@compamy.com';                            // SMTP username
$mail->Password = '<password>';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted

$mail->From = 'team@compamy.com';
$mail->FromName = 'Team Scaleqa';
$mail->addAddress($_POST['email_address'], '');  // Add a recipient
$mail->addAddress('team@compamy.com');               // Name is optional
$mail->addReplyTo('team@compamy.com', 'Team Scaleqa');
$mail->addCC('team@compamy.com');
$mail->addBCC('team@compamy.com');



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

$mail->Subject = 'Welcome to Company';
$pos = strpos( $_POST['email_address'], "@");

$username = substr($_POST['email_address'], 0, $pos);
$mail->Body = "
    Hi 
    ";
//echo $mail->Body;
//$mail->Body    = clone $message;
$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;
       exit;
    }

    echo 'Message has been sent';
}

?>

</body>
</html>
  • 写回答

1条回答 默认 最新

  • doulang5323 2014-04-27 18:34
    关注

    GMail has strong spam filters. One of them checks that the sender is a valid MTA. In your EHLO greeting you use "localhost", which is not what a regular server would do. Even when this script runs from a server, GMail runs a reverse DNS lookup to ensure your domain corresponds to your server's IP, otherwise it is classified as spam.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效