简体   繁体   English

php联系人表单,可在收件箱中显示发件人的电子邮件地址

[英]php contact form to display the email address of the sender in inbox

I would like to create a form that will simply allow the recipient of the messages the ability to click 'reply to' when responding to a website message from their inbox. 我想创建一个表单,该表单将仅允许邮件的收件人在从收件箱中回复网站消息时单击“回复”。 The reply should auto populate with the sender's email address. 回复应自动使用发件人的电子邮件地址填充。

I think that I need to change the $mailheader from a specific email address to .$_POST, but my attempts are not working correctly. 我认为我需要将$ mailheader从特定的电子邮件地址更改为。$ _ POST,但是我的尝试无法正常工作。 I feel like it must be something small that I am doing incorrectly. 我觉得这一定是我做错了的小事。

Here is the php form code. 这是php表单代码。 It is working as is, but I am attempting to edit/improve usability: 它正在按原样工作,但是我正在尝试编辑/改善可用性:

<?
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$security = $_POST['security'];

$to = "website-owner@gmail.com";
$subject = "Contact Message from Website";
$message = "A visitor of exampledomain.com has submitted the following message.\n\nName: $name\n\nEmail: $email\n\nPhone: $phone\n\nMessage: $message";
$mailheaders = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";


if ($security=="10") {
    mail($to,$subject,$message,$mailheaders);
    header("Location:contact.php?s=1");
}
else {
    header("Location:contact.php?s=2");
}
?>

This was my first attempt: 这是我的第一次尝试:

$mailheader = "From: ".$_POST["email"]."\r\nReply-To: ".$_POST["email"]."\r\n";

This was my second attempt: 这是我的第二次尝试:

$mailheaders .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheaders .= "From: ".$_POST['Email']."\r\n";

This was my third attempt: 这是我的第三次尝试:

$mailheaders = "Reply-To: ".$_POST["email"]."\r\n";
$mailheaders = "From: ".$_POST['Email']."\r\n";

I figured it out! 我想到了! This mail header works. 该邮件头有效。

$mailheaders = 'From: webmaster@example.com' . "\r\n" .
        'Reply-To: ' . $email . "\r\n" .
        'X-Mailer: PHP/' . phpversion();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM