在php中使用hotmail smtp发送邮件

时间:2014-03-09 06:15:59

标签: php email phpmailer

我正在尝试通过PHPMailer发送电子邮件。虽然发送它给我错误 SMTP错误:无法连接到服务器:连接超时(110)SMTP连接()失败。邮件程序错误:SMTP连接()失败。

我真的无法弄清楚出了什么问题。是服务器配置问题还是代码配置问题。如果有人知道答案,请告诉我。

以下代码:

require_once('class.phpmailer.php');
include('class.smtp.php');
$mail             = new PHPMailer(); //Initialize a new PHPMailer object;
$body            = eregi_replace("[\]",'',$body); //Replace unwanted characters of the content
$mail->CharSet ="ISO-8859-1";
$mail->IsSMTP(); 
$mail->SMTPDebug  = 1;                

$mail->From = 'email';
$mail->FromName = 'name';
$mail->SMTPAuth   = true;                  
$mail->SMTPSecure = "ssl";                
$mail->Host       = 'smtp.live.com';     
$mail->Port       = '465';                  
$mail->Username   = 'email ';  
$mail->Password   = 'password';           
$mail->SetFrom('email', 'who');
$mail->AddReplyTo('email','who');
$mail->Subject    = $subject;
$mail->AltBody    = 'To view the message, please use an HTML compatible email viewer!'; 
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, '');

if(!$mail->Send()) {

    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
   echo "Message sent successfully!";
}

0 个答案:

没有答案