更改发件人地址

时间:2016-10-27 12:30:03

标签: php email

我正在尝试将脚本中的电子邮件更改为发送它的人,以便我可以直接回复表单发送的邮件。在发送消息的时刻,似乎来自User@servername.com的表单我想将其更改为填写表单的人的地址。 我不懂php,请帮助。

<?php    
$subject = 'Message from Website'; // Subject of your email
$to = 'me@mydomain.com';  //Recipient's E-mail
$emailTo = $_REQUEST['email'];

$headers = "MIME-Version: 1.1";
$headers .= "Content-type: text/html; charset=iso-8859-1";
$headers .= "From: " . $emailTo . "\r\n"; // Sender's E-mail
$headers .= "Return-Path:". $emailTo;

$message .= 'Name : ' . $_REQUEST['name'] . "\n";
$message .= 'Email : ' . $_REQUEST['email'] . "\n";
$message .= 'Phone : ' . $_REQUEST['phone'] . "\n";
$message .= 'Message : ' . $_REQUEST['message'];

if (@mail($to, $subject, $message, $headers))
{
    // Transfer the value 'sent' to ajax function for showing success message.
echo 'sent';
}
else
{
// Transfer the value 'failed' to ajax function for showing error message.
echo 'failed';
}
?>

1 个答案:

答案 0 :(得分:0)

我认为您的标题未正确读取标题需要一致使用 \ r \ n 来结束标题行。请仔细阅读the manual中的示例,看看它是否对您有所帮助:

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);