我需要帮助 . 我的联系表单没有向我的Gmail发送消息 . 我也检查了我的垃圾邮件,没有任何结果 . 不确定这是否与我的代码有关 . 提前致谢 . 我已经意识到这条消息正在进入我的godaddy cpanel . 主题是
邮件失败 - 收件人地址格式错误
消息体说
您发送的邮件包含错误构造的收件人地址:from:缺少或格式错误的本地部分(期望word或“<”)邮件尚未传递给任何收件人 .
还请忽略 $ip
字段,表示我的代码部分未添加 .
<?php
$emailErr = "";
$commentErr = "";
if(isset($_POST['submit'])){
//declares variable
$email = $_POST['email'];
$comment = $_POST['comment'];
if(empty($_POST['email'])){
$emailErr = "Please enter your email";
}
if(empty($_POST['comment'])){
$commentErr = "comment field can't be empty";
}
}
if(!empty($_POST['email']) && !empty($_POST['comment'])){
// Send the email
$to = "myname@gmail.com";
$email = "From: $email";
$comment = "Message: $comment";
$message = "$message" . "\n\n\n==- Sent from the website with IP Address: " . $ip . " -==";
$headers = "From: $email,";
$send_contact = mail($to,$email,$comment,$message,$headers);
header("Location: index.php");
}
?>
2 回答
这应该工作 .
我建议你学习如何在这里使用邮件功能http://php.net/manual/en/function.mail.php
Heyy早安,
如果您在离线模式下工作,可能需要phpmailer .
首先你需要从这里下载phpmailer https://github.com/PHPMailer/PHPMailer/archive/master.zip
然后粘贴到您的文件夹中 . 如果我的编码不能清除您,您可以查看
https://github.com/PHPMailer/PHPMailer
第二种方式 .
如果您在在线模式下进行测试(拥有自己的域和托管),则可以随意复制和粘贴 .
不需要phpmailer .