我在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