请有人建议我使用yahoo smatp和php发送邮件的代码..
require("class.phpmailer.php"); // be sure to change this to your location!
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.mail.yahoo.com"; // sets yahoo as the SMTP server
$mail->Port = 25; // set the SMTP port
$mail->Username = "sumthing@yahoo.com"; // yahoo username
$mail->Password = "password"; // yahoo password
$mail->From = "sumthing@yahoo.com";
$mail->FromName = "myname";
$mail->AddAddress("you@example.com");
$mail->Subject = "Test PHPMailer Message";
$mail->Body = "Hi! \n\n This was sent with phpMailer_example3.php.";
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
此代码给出了错误“无法连接到SMTP主机”。
答案 0 :(得分:0)
许多提供SMTP的网站不支持SSL(SMTP-S)。如果支持通常位于不同的端口,例如465.连接到465通常会失败。尝试评论
$mail->SMTPSecure = "ssl"
首先尝试不进行身份验证,以确保连接正常。