2012-04-27 38 views
2

目前我正在嘗試使用PHPmailer發送電子郵件。這裏有以下PHP連接到Hotmail發送電子郵件?

​​

代碼我試過SSL,端口587 smtp.live.com與PHPMailer的,爲什麼不工作?

錯誤是「SMTP錯誤:無法連接到SMTP主機。郵件程序錯誤:SMTP錯誤:無法連接到SMTP主機。」

我不能telnet smtp.live.com 25,587。 smtp.gmail.com等等。我該怎麼辦? :(

+0

你是什麼意思「我不能'telnet'爲'smtp.live.com'」是什麼意思?你遇到了什麼錯誤? – icktoofay 2012-04-27 03:07:01

+0

無法打開連接到端口25上的主機;連接失敗。 – user127886 2012-04-27 03:14:34

+0

@ user127886,您的主機很可能會阻止這些端口。是很常見。 – Brad 2012-04-27 03:15:36

回答

0

端口587爲我工作。

不需要運行IsSMTP()。它註釋掉,因爲它會拋出異常。

不要忘記將其標記爲答案,如果它解決您的問題:)

+0

你的答案是不真實的 – Julian 2014-02-04 13:38:14

2
<?php 

//error_reporting(E_ALL); 
error_reporting(E_STRICT); 

date_default_timezone_set('America/Toronto'); 

require_once('../class.phpmailer.php'); 
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded 

$mail    = new PHPMailer(); 

$body    = file_get_contents('contents.html'); 
$body    = eregi_replace("[\]",'',$body); 

$mail->IsSMTP(); // telling the class to use SMTP 
$mail->SMTPDebug = 2;      // enables SMTP debug information (for testing) 
              // 1 = errors and messages 
              // 2 = messages only 
$mail->SMTPAuth = true;     // enable SMTP authentication 
$mail->SMTPSecure = "tls";     // sets the prefix to the servier 
$mail->Host  = "smtp.live.com";  // sets hotmil as the SMTP server 
$mail->Port  = 587;     // set the SMTP port for the hotmail server 
$mail->Username = "[email protected]";  // hotmail username 
$mail->Password = "useyourownpassword";   // hotmail password 
$mail->SetFrom('[email protected]', 'First Last'); 
$mail->AddReplyTo("[email protected]","First Last"); 
$mail->Subject = "PHPMailer Test Subject via smtp (hotmail), basic"; 
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 
$mail->MsgHTML($body); 

$address = "[email protected]"; 
$mail->AddAddress($address, "John Doe"); 

$mail->AddAttachment("images/phpmailer.gif");  // attachment 
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment 

if(!$mail->Send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo "Message sent!"; 
} 

?> 
+0

謝謝您的回覆 – Talha 2015-10-02 06:58:04

2

Talha答案是適合我的作品。嘗試評論$ mail-> IsSMTP();我也評論過這部分$ mail-> Port = 587;

相關問題