我正在努力找到这个php表单中的错误。我以各种可能的方式对其进行了编辑,并且表单在我的网站上提交,但是我从未收到任何已发送的表单到我的电子邮件中。有人会非常友好地查看下面的代码以获取我的mail.php表单吗? TIA
阿曼达
<?
require("class.phpmailer.php");
//form validation vars
$formok = true;
$errors = array();
//sumbission data
$ipaddress = $_SERVER['REMOTE_ADDR'];
$date = date('d/m/Y');
$time = date('H:i:s');
//form data
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = 'tls';
$mail->Username = "dont.reply.m@gmail.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$mail->From = "dont.reply.m@gmail.com"; // SMTP username
$mail->AddAddress("mypersonalemail@msn.com"); // Your Address
$mail->Subject = "New Message from your website!";
$mail->IsHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Body = "<p>You have recieved a new message from the contact form on your website.</p>
<p><strong>Name: </strong> {$name} </p>
<p><strong>Email Address: </strong> {$email} </p>
<p><strong>Subject: </strong> {$subject} </p>
<p><strong>Message: </strong> {$message} </p>
<p>This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</p>";
if(!$mail->Send())
{
echo "Mail Not Sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Mail Sent";
?>
答案 0 :(得分:0)
尝试添加$ mail-&gt;端口= 587并参考以下链接。有时$ mail-&gt; SMTP安全应该是SSL,以防除了TLS以外的gmail
这是使用Gmail设置发送电子邮件的完整参考
答案 1 :(得分:0)
如果您在localhost中进行测试,请确保已安装邮件服务器。
如果在线尝试使用有效信息
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = 'tls';
$mail->Username = "dont.reply.m@gmail.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$mail->From = "dont.reply.m@gmail.com"; // SMTP username
替换那些为实物