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



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



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

    echo 'Message has been sent';


  • 写回答

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 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题