我使用下面的简单代码使用php发送邮件。当我回显$headers = "From: . $email\r\n"; //echo $headers; exit;
之类的行From: . test@email.com
时。
我发现dot是在邮件地址之前打印的,所以邮件即将发布但不正确。如果我删除了点,邮件甚至都没有来。这段代码有什么问题?
<?php
if (isset($_REQUEST['user_email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['user_email'];
$user_name = $_REQUEST['user_name'];
$user_message = $_REQUEST['user_message'];
include 'contact_mail_form.php';
$to = "testtest@gmail.com";
$message = $contactText;
$subject = "Test Mail";
$headers = "From: . $email\r\n"; //echo $headers; exit;
$headers .= "Content-type: text/html\r\n";
mail($to,$subject,$message,$headers);
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
?>
<form id="contact_form" name="ContactForm" action="" method="post" onsubmit="return checkContact(this);">
<div class="wrapper">
<div class="fright">
<div class="name">Message:</div>
<textarea cols="1" rows="1" name="user_message" id="user_message" ></textarea>
<span class="clear"></span> </div>
<div class="fleft">
<div>
<div class="name">Your Name:</div>
<input type="text" class="input" name="user_name" id="user_name" />
<span class="clear"></span> </div>
<div>
<div class="name">E-mail:</div>
<input type="text" class="input" name="user_email" id="user_email" />
<span class="clear"></span> </div>
</div>
</div>
<div class="buttons"><a class="more" href="javaScript:void(0);" onClick="document.getElementById('contact_form').reset()">clear</a> <input class="more1" type="SUBMIT" class="button2" value="Send" name="" /> </div>
</form>
<?php } ?>
答案 0 :(得分:3)
尝试这样你的点作为字符串而不是连接
$headers = "From:" . $email."\r\n";
可能因为\r\n
应该被"
而不是'
还
$headers .= 'Content-type: text/html'. "\r\n";