简体   繁体   English

PHP的联系方式回复发件人

[英]php contact form reply to sender

The following code is sending an email from my website, but the email comes from cgi-mailer@kundenserver.de , how do i change this to the sender's email address, which i have given the variable $email : 以下代码从我的网站发送电子邮件,但是电子邮件来自cgi-mailer@kundenserver.de ,我如何将其更改为发件人的电子邮件地址,该地址已赋予变量$email

<?php
if(isset($_POST['submit'])) {
    $msg = 'Name: ' .$_POST['FirstName'] .$_POST['LastName'] ."\n" 
    .'Email: ' .$_POST['Email'] ."\n" 
    .'Message: ' .$_POST['Message'];
$email = $_GET['Email'];
    mail('me@example.com', 'Message from website', $msg );
    header('location: contact-thanks.php');

    } else {
header('location: contact.php');
exit(0);
}
?>

Adding the header From: to my mail command seems to allow me to change the email address, but i can't work out how to do it to the variable. 在我的邮件命令中添加标题From:似乎允许我更改电子邮件地址,但是我不知道如何对变量进行操作。

Declare the variable in the headers.. 在标题中声明变量。

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

Edit: 编辑:

<?php
if(isset($_POST['submit'])) {
    $msg = 'Name: ' .$_POST['FirstName'] .$_POST['LastName'] ."\n" 
    .'Email: ' .$_POST['Email'] ."\n" 
    .'Message: ' .$_POST['Message'];
$email = $_GET['Email'];
$headers = 'From: '.$email."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    mail('me@example.com', 'Message from website', $msg, $headers );
    header('location: contact-thanks.php');

    } else {
header('location: contact.php');
exit(0);
}
?>
<?php

$to = "someone@example.com";

$subject = "Test mail";

$message = "Hello! This is a simple email message.";

$from = "someonelse@example.com";

$headers = "From:" . $from;

mail($to,$subject,$message,$headers);

echo "Mail Sent.";

?>

For more reference 更多参考

http://php.net/manual/en/function.mail.php http://php.net/manual/en/function.mail.php

Add this to the header 将此添加到标题

$headers .= 'From: ' . $from . "\r\n";
$headers .='Reply-To: $from' . "\r\n" ;
mail($to,$subject,$message,$headers);

It should set the sender. 它应该设置发送者。

where 哪里

$from= "Marie Debra <marie.debra@website.com>;"
$from = $_POST['email']; $headers = array('Content-Type: text/plain; charset="UTF-8";', 'From: ' . $from, 'Reply-To: ' . $from, 'Return-Path: ' . $from, );

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

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