我会在联系表单中使用PHPMailer,但是我做错了事,因为它不起作用。
<?php
require ("class.phpmailer.php");
if (isset($_POST['submit'])) {
$name=$_POST['name'];
$subject=$_POST['subject'];
$email=$_POST['email'];
$message=$_POST['message'];
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.mail.com";
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->Username = 'myemail@mail.com';
$mail-> Password = 12345;
$mail->From = ($email);
$mail->FromName = ($name);
$mail->addAddress = 'myemail@mail.com';
$mail->isHTML(false);
$mail->Subject = "Enquiry from Website submitted by $name";
}
if (!$mail->Send()) {
echo "<script>alert('Submission failed.');</script>";``
}
else {
echo "<script>alert('Email has been sent successfully.');</script>";
}
?>
您愿意为我提供一些帮助吗?我不明白我在哪里做错了。
谢谢。
答案 0 :(得分:0)
如果检查调试输出,则可以找到提示。最可能的原因是参数不正确,或者smtp服务器拒绝了请求。
请发布调试输出。