我在PHP新手。我試圖使用PHP發送電子郵件,但我不知道我的代碼中有什麼問題。我GOOGLE了很多,但沒有任何工作。這是我的PHP代碼。我使用class.phpmailer.php。無法發送電子郵件使用核心php
<?php
require("phpmailer-master/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "mypassword"; // SMTP password
$webmaster_email = "[email protected]"; //Reply to this email ID
$email="[email protected]"; // Recipients email ID
$name="myname"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Webmaster";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
你得到了什麼錯誤@Pooja? – 2014-09-06 06:59:56
什麼都沒有。只是一個空白頁面,我甚至看到了控制檯。 – 2014-09-06 07:01:28
上面的代碼是否正確,或者是剪切和粘貼時最後幾行是否重複。第6行IsSMTP(); //通過SMTP發送,應該被刪除 – bumperbox 2014-09-06 07:02:39