目前我正在尝试使用 PHPmailer 发送电子邮件。这是下面的代码
<?php
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer(); // ---------- adjust these lines --------------------------- ------------
$mail->Username = "([email protected] /cdn-cgi/l/email-protection)"; // your hotmail user name
$mail->Password = "password";
$mail->AddAddress"([email protected] /cdn-cgi/l/email-protection)"; // recipients email
$mail->FromName = "test"; // readable name
$mail->Subject = "Subject title";
$mail->Body = "Here is the message you want to send to your friend.";
//-----------------------------------------------------------------------
$mail->Host = "smtp.live.com"; // GMail
$mail->Port = 25; $mail->IsSMTP(); // use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->From = $mail->Username;
if(!$mail->Send())
echo "Mailer Error: " . $mail->ErrorInfo;
else
echo "Message has been sent";
?>
我已经使用 PHPMailer 尝试了 smtp.live.com 的 SSL、端口 587,为什么它不起作用?
错误为“SMTP 错误:无法连接到 SMTP 主机。邮件程序错误:SMTP 错误:无法连接到 SMTP 主机。”
我无法远程登录 smtp.live.com 25,587。
smtp.gmail.com 等等等等。我该怎么办? :(
<?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] /cdn-cgi/l/email-protection"; // hotmail username
$mail->Password = "useyourownpassword"; // hotmail password
$mail->SetFrom('[email protected] /cdn-cgi/l/email-protection', 'First Last');
$mail->AddReplyTo("[email protected] /cdn-cgi/l/email-protection","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] /cdn-cgi/l/email-protection";
$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!";
}
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)