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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵