2017-09-14 93 views
0

我是非常新的PHP和即時通訊嘗試建立一個郵政局長,我使用Hostbuddy爲我的託管站點,並下載了我的服務器的SMTP信息。Hostbuddy SMTP郵件測試,有問題,無法連接到SMTP主機

,我從他們這些文件自動上傳到我的服務器用於測試SMTP:

class.phpmailer.php 
class.smtp.php 
index.php 
web.config 

我想我進入了測試的正確信息。但我不斷收到回覆,說:「無法連接到SMTP服務器」。

這裏是index.php所以你們可以看到發生了什麼。

<Center><h2>PHP Test Email Script</h2></center> 
<?php 
// display form if user has not clicked submit 
if (!isset($_POST["submit"])) { 
    ?> 
    <form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>" target="_blank"> 
<Table align = center> 

    <tr><td>From Email: <td><input type="text" name="uname"> i.e [email protected]</tr> 
    <tr><td>Email Password: <td><input type="password" name="pass"></tr> 
<tr><td>Host: <td><input type="text" name="host"> i.e Mail.YourDomain.com</tr> 
<tr><td>To:<td> <input type="text" name="to"></tr> 

    <tr><td colspan =2 align = center><input type="submit" name="submit" value="Send Email"></tr> 
</table> 
    </form> 

    <?php 
} 
else { // the user has submitted the form 

include("class.phpmailer.php"); //you have to upload class files "class.phpmailer.php" and "class.smtp.php" 

$mail = new PHPMailer(); 

$mail->IsSMTP(); 
$mail->SMTPAuth = true; 

$mail->Host = $_POST["host"]; 

$mail->Username = $_POST["uname"]; 
$mail->Password = $_POST["pass"]; 

$mail->From = $_POST["uname"]; 
$mail->FromName = "demouser"; 

$mail->AddAddress($_POST["to"],"test"); 
$mail->Subject = "This is the subject"; 
$mail->Body = "This is a sample message using SMTP authentication"; 
$mail->WordWrap = 50; 
$mail->IsHTML(true); 
$str1= "gmail.com"; 
$str2=strtolower($_POST["uname"]); 
If(strstr($str2,$str1)) 
{ 
$mail->SMTPSecure = 'tls'; 
$mail->Port = 587; 
if(!$mail->Send()) { 
echo "Mailer Error: " . $mail->ErrorInfo; 
echo "<br><br> * Please double check the user name and password to confirm that both of them are correct. <br><br>"; 
echo "* If you are the first time to use gmail smtp to send email, please refer to this link :http://www.smarterasp.net/support/kb/a1546/send-email-from-gmail-with-smtp-authentication-but-got-5_5_1-authentication-required-error.aspx?KBSearchID=137388"; 
} 
else { 
echo "Message has been sent"; 
} 
} 
else{ 
    $mail->Port = 25; 
    if(!$mail->Send()) { 
echo "Mailer Error: " . $mail->ErrorInfo; 
echo "<br><BR>* Please double check the user name and password to confirm that both of them are correct. <br>"; 
} 
else { 
echo "Message has been sent"; 
} 
} 
} 
?> 

任何信息將是偉大的,在此先感謝!

+0

這個答案可以幫助(或者一個愚蠢?):https://stackoverflow.com/questions/13489037/could-not-connect-to-smtp-host?rq = 1 – Jeff

回答

0

您需要添加真正的SMTP的Gmail,所以你可以添加:

smtp-relay.gmail.com smtp.gmail.com aspmx.l.google.com 

設置要求

Options : port 25, 465 ou 587 
Protocoles SSL/TLS (Secure Socket Layer/Transport Layer Security) 

Port 465 (SSL require). 
Port 587 (TLS require). 
Adresses dynamic IP allowed. 

Port 25. 
TLS no require. 
Adresses dynamic IP allowed. 
0

看起來像我有它設置正確,它只是花了幾個小時的hostbuddy讓smtp服務器設置。現在效果很好:)感謝您的建議!

相關問題