2017-09-14 147 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服务器设置。现在效果很好:)感谢您的建议!

相关问题