我正在使用我在教程中找到的联系表单脚本,它运行正常 . 主题和消息联系人通过,但发件人电子邮件不会 . 发件人姓名和电子邮件不会通过 . 当我检查从表单收到的电子邮件时,它在收件箱中显示“未知发件人”,当我查看该邮件时,它说它是通过主机发送的 .
任何人都可以看到我出错的地方吗?我对联系表单没有太多经验,需要很快完成客户端站点 .
表单的HTML在这里:
<form action="#" id="form" method="post" name="form">
<input name="vname" placeholder="Your Name" type="text" value="">
<input name="vemail" placeholder="Your Email" type="text" value="">
<input name="sub" placeholder="Subject" type="text" value="">
<label>Your Suggestion/Feedback</label>
<textarea name="msg" placeholder="Type your text here...">
</textarea>
<input id="send" name="submit" type="submit" value="Send Feedback">
</form>
<h3><?php include "secure_email_code.php" ?>
</h3>
PHP代码在这里:
<?php
if(isset($_POST["submit"])){
// Checking For Blank Fields..
if($_POST["vname"]=="" || $_POST["vemail"]=="" ||
$_POST["sub"]=="" || $_POST["msg"]=="")
{
echo "Fill All Fields..";
}else{
// Check if the "Sender's Email" input field is filled out
$email=$_POST['vemail'];
// Sanitize E-mail Address
$email =filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate E-mail Address
$email= filter_var($email, FILTER_VALIDATE_EMAIL);
if (!$email){
echo "Don't forget to include your email adress! Otherwise we can't get back to you.";
}
else{
$subject = $_POST['sub'];
$message = $_POST['msg'];
$headers = 'From:'. $email2 . "\r\n"; // Sender's Email
$headers .= 'Cc:'. $email2 . "\r\n"; // Carbon copy to Sender
// Message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message, 70);
// Send Mail By PHP Mail Function
mail("marc@example.com", $subject, $message, $headers);
echo "Thanks for getting in touch! We'll get back to you ASAP.";
}
}
}
?>
如果我用条目中的 email@provider.com
硬编码 Headers ,则发送的邮件会替换为 @webhost.com
示例:我输入 me@gmail.com
并且发送电子邮件说明来自 me@webhost.com
这是我的提供商的问题吗?
目前代码:
<?php
if(isset($_POST["submit"])){
// Checking For Blank Fields..
if($_POST["vname"]==""||$_POST["vemail"]==""||$_POST["sub"]==""||$_POST["msg"]==""){
echo "Fill All Fields.";
}else{
// Check if the "Sender's Email" input field is filled out
$email=$_POST['vemail'];
// Sanitize E-mail Address
$email =filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate E-mail Address
$email= filter_var($email, FILTER_VALIDATE_EMAIL);
if (!$email){
echo "Don't forget to include your email adress! Otherwise we can't get back to you.";
}
else{
$subject = $_POST['sub'];
$message = $_POST['msg'];
$headers = 'From:' . 'Ross@gmail.com' . "\r\n"; // Sender's Email
$headers .= 'Cc: chad' . "\r\n"; // Carbon copy to Sender
$from = $headers;
// Message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message, 70);
// Send Mail By PHP Mail Function
mail("marc.murray.92@gmail.com", $subject, $message, $headers);
echo "Thanks for getting in touch! We'll get back to you ASAP.";
}
}
}
?>
2 回答
试试phpMailer:https://github.com/PHPMailer/PHPMailer
试试这个: