<? require "phpmailer/class.phpmailer.php"; $mail = new PHPMailer(); $mail->IsSMTP(); // set mailer to use SMTP $mail->Host = "SMTP.163.com"; // 邮件供应商的服务器地址 specify main and backup server $mail->SMTPAuth = true; // 验证开启 turn on SMTP authentication $mail->Username = "cy14yang"; // 你的邮箱用户名 SMTP username $mail->Password = "*********"; // 你的邮箱密码 SMTP password$mail->From = "[email protected]"; //发件箱地址 $mail->FromName = "cy14yang"; //发送者姓名 $mail->AddAddress("[email protected]", "ad"); //收件箱地址 //$mail->AddAddress("[email protected]"); // name is optional //$mail->AddReplyTo("[email protected]", "Information");$mail->WordWrap = 50; // set word wrap to 50 characters //$mail->AddAttachment("file.txt"); // 添加附件 add attachments //$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name $mail->IsHTML(true); // set email format to HTML$mail->Subject = "Here is the subject1111111111111111"; //邮件标题 $mail->Body = "This is the HTML message body 111111111<b>in bold!</b>"; //邮件内容可带HTML $mail->AltBody = "This is the body in plain text for non-HTML mail clients"; //邮件内容不带HTMLif(!$mail->Send()) { echo "Message could not be sent. <p>"; echo "Mailer Error: " . $mail->ErrorInfo; exit; }else{echo "Message has been sent";} ?>
为什么产生 Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host.
require "phpmailer/class.phpmailer.php";
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "SMTP.163.com"; // 邮件供应商的服务器地址 specify main and backup server
$mail->SMTPAuth = true; // 验证开启 turn on SMTP authentication
$mail->Username = "cy14yang"; // 你的邮箱用户名 SMTP username
$mail->Password = "*********"; // 你的邮箱密码 SMTP password$mail->From = "[email protected]"; //发件箱地址
$mail->FromName = "cy14yang"; //发送者姓名
$mail->AddAddress("[email protected]", "ad"); //收件箱地址
//$mail->AddAddress("[email protected]"); // name is optional
//$mail->AddReplyTo("[email protected]", "Information");$mail->WordWrap = 50; // set word wrap to 50 characters
//$mail->AddAttachment("file.txt"); // 添加附件 add attachments
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name
$mail->IsHTML(true); // set email format to HTML$mail->Subject = "Here is the subject1111111111111111"; //邮件标题
$mail->Body = "This is the HTML message body 111111111<b>in bold!</b>"; //邮件内容可带HTML
$mail->AltBody = "This is the body in plain text for non-HTML mail clients"; //邮件内容不带HTMLif(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}else{echo "Message has been sent";}
?>
Message could not be sent.
Mailer Error: SMTP Error: Could not connect to SMTP host.
phpinfo()中没有
Sockets Support = enable
为什么
windows上直接去掉php.ini中关于socket的dll.
并且确定php_sockets.dll 在正确的目录.
改成 $mail->Username = "[email protected]";
再试试。