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.

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

报告相同问题?

悬赏问题

  • ¥15 综合布线实例设计,就好看好看不恐怖可好滤镜好聚
  • ¥15 使用moviepy库视频合并时出错
  • ¥30 FLUENT液固传质UDF
  • ¥15 怎么看梯度直方图以,怎么判断梯度消失/爆炸,怎么解决
  • ¥15 aspnetdll文件访问拒绝
  • ¥15 wpf中在模版中寻找元素
  • ¥15 MFC平台生成指定圆
  • ¥15 jmeter出现403
  • ¥500 求华为P30PRO手机硬盘数据恢复
  • ¥15 关于#vscode#的问题:ESP32开发板对接MQTT实现小灯泡的开关