请帮助我,我是 PHP 新手,自从过去 5 小时以来,我一直在尝试发送邮件,现在真的很累。谢谢。
这是我的代码。我正在使用 Gmail 帐户。
include("class.phpmailer.php");
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = $mail->getFile('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP();
$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 = "hussaintalha@gmail.com"; // GMAIL username
$mail->Password = "xxxxxxxx"; // GMAIL password
$mail->AddReplyTo("hussaintalha@gmail.com","First Last");
$mail->From = "hussaintalha@gmail.com.com";
$mail->FromName = "First Last";
$mail->Subject = "PHPMailer Test Subject via gmail";
//$mail->Body = "Hi,<br>This is the HTML BODY<br>"; //HTML Body
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddAddress("hussaintalha@gmail.com", "John Doe");
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
当我运行我的文件时,出现此错误:
警告:fopen(contents.html) [function.fopen]: 无法打开流:第 1870 行的 D:\xampplite\htdocs\WebEng\class.phpmailer.php 中没有这样的文件或目录
警告:fsockopen() [function.fsockopen]:无法连接到 ssl://smtp.gmail.com:465(无法找到套接字传输“ssl” - 您在配置 PHP 时是否忘记启用它?) D:\xampplite\htdocs\WebEng\class.smtp.php 在第 122 行邮件程序错误:SMTP 错误:无法连接到 SMTP 主机。