2014-04-27 120 views
0

我試圖在提交表單時向用戶發送郵件。我在本地主機和我的服務器上都有相同的代碼,它們都是在ubuntu上運行的。在我的本地主機上,我的SMTP連接()失敗,雖然它在我的服務器上正常工作,表明我的本地計算機上的php/smtp設置配置錯誤,但我無法弄清楚什麼。以下是我在本地計算機上得到的錯誤信息。在發送郵件時,SMTP連接()在php中失敗錯誤

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. 

以下是我的html代碼

<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 = '[email protected]';       // SMTP username 
$mail->Password = '<password>';       // SMTP password 
$mail->SMTPSecure = 'tls';       // Enable encryption, 'ssl' also accepted 

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



$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

GMail中具有較強的垃圾郵件過濾器。其中一人檢查發件人是否爲有效的MTA。在您的EHLO問候語中,您使用「localhost」,這不是常規服務器的功能。即使此腳本從服務器運行,GMail也會運行反向DNS查找以確保您的域對應於您的服務器的IP,否則它將被歸類爲垃圾郵件。

+0

有什麼辦法可以讓我的本地主機上工作嗎?否則,發展對我來說可能是困難的。 – raju

+0

我不知道,也許有。出於測試目的,考慮在gmail以外的服務器上進行測試。 –

+0

我想我在這裏有同樣的問題。奇怪的是,如果我嘗試使用我的谷歌應用程序的電子郵件帳戶之一,它的作品。我現在不知道該怎麼做...... –

相關問題