我正在尝试设置新的联系表单。我能够正确地收到电子邮件和消息,但回复显示为(未知发件人)或我姓名服务器上的用户名,例如:coggi132@rs14.websitehostserver.net。我现在已经看了4个小时,删除并添加了我在网上看过的不同内容。如果我将电子邮件地址硬编码到邮件(..." $ visitor_email")部分,它确实有效。感谢
这是html:
<form id="form" action="../assets/form-to-email.php" method="post">
<p><label class="required" for="namet">Name</label>(required)<br /><input name="name" id="name" type="text" required/>
<input type="text" style="display:none;" id="zip" name="zip" placeholder="Leave this field blank" autocomplete="off"></p>
<p><label class="required" for="mailt">E-mail</label>(required)<br /><input name="email" id="email" type="text" required/></p>
<p><label for="phone">Phone</label><br /><input name="phone" id="phone" type="text" required/></p>
<p><label class="required" for="message">Message</label>(required)<br /><textarea name="message" id="message" required></textarea></p>
<p><input class="btn_m" type="submit" name="submit" value="Submit Form" /></p>
</form>
这里是php
<?php
/*
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}*/
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST['phone'];
$email_subject = "New Message From NovaWebDev.com Form";
$email_body = "You have received a new message from $name.\n
Phone Number: $phone \n
Here is the message: $message \n".
$to = "info@novawebdev.com";//<== Website's email address
$headers = "From: $visitor_email \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body, $headers);
//done. redirect to success page.
header('Location: /index.php/shared/email_success');
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
答案 0 :(得分:0)
使用此功能;
$headers = 'From: ' . $visitor_email . "\r\n";
$headers .= 'Reply-To: ' . $visitor_email . "\r\n";
答案 1 :(得分:0)
我想出来了。我的电子邮件输入名为&#34; mail&#34;,而我的php是&#34; email&#34;。谢谢你的帮助。