PHP邮件程序类不能与PHP-xamp一起使用
我有下面的代码,这是给和错误PHP邮件程序类不能与PHP-xamp一起使用,php,apache,xampp,phpmailer,Php,Apache,Xampp,Phpmailer,我有下面的代码,这是给和错误 <?php require_once('phpmailer/class.phpmailer.php'); $mail = new PHPMailer(true); $mail->IsSendmail(); //Send mail using gmail $mail->IsSMTP(); // telling the class to use SMTP $mail->SMTPAuth = true; // enable SMTP auth
<?php
require_once('phpmailer/class.phpmailer.php');
$mail = new PHPMailer(true);
$mail->IsSendmail();
//Send mail using gmail
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "myemail@gmail.com"; // GMAIL username
$mail->Password = "mypassword"; // GMAIL password
$mail->From = "myemail@gmail.com";
$mail->FromName = "Online Request";
$mail->AddAddress("receiver_email@gmail.com","myself");
$mail->Subject = "Here is the subject";
$mail->Body = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
错误是
致命错误:在C:\Softwares\xampp\htdocs\email\u testing\phpmailer\class.phpmailer.php:1193中出现未捕获的异常“phpmailerException”,消息“SMTP connect()失败”
堆栈跟踪:
0 C:\Softwares\xampp\htdocs\email\u testing\phpmailer\class.phpmailer.php(1036):phpmailer->smtpSend('Date:Thu,31 J.,'--b1_02dd62dba5…)
1 C:\Softwares\xampp\htdocs\email\u testing\phpmailer\class.phpmailer.php(943):phpmailer->postSend();2 C:\Softwares\xampp\htdocs\email\u testing\test.php(25):phpmailer->send()
第1193行的C:\Softwares\xampp\htdocs\email\u testing\phpmailer\class.phpmailer.php中抛出了3{main}
im在PHP5.3.8、apache 2.2.2.1、xamp 1.7.7版中使用xamp
有什么想法吗?感谢您的帮助我可以假设您的开发机器具有正常的Internet连接吗?您启用了openSSL扩展吗?请参阅@Alz,它是
getErrorMessage()
,但我们已经知道它是什么(“SMTP连接()失败”)。我建议您将echo$mail->ErrorInfo
添加到您的catch
块中。此错误通常是由环境问题引起的-被ISP防火墙阻止、DNS故障等。对于gmail,您应该设置SMTPSecure='tls'
和Port=587
。我还猜想您使用的是一个旧版本(或者您从一个旧示例中复制了yoru代码)。获取最新信息。好吧,你就在这里-找出是什么阻止了你的访问,PHPMailer也将开始工作。