PHP 回复错误 - 需要个人的电子邮件,而不是管理员


PHP reply-to error - need person's email, not admin

我有下面的PHP联系表格,其中包含验证码以确保正确。但是,当我回复来自网站的电子邮件时,它会随机放置一封电子邮件,我相信这是服务器管理员,但是,我希望它是发送表单的人电子邮件。下面是代码,你能帮我吗?

<?php session_start();
if(isset($_POST['Submit'])) {   if( $_SESSION['chapcha_code'] == $_POST['chapcha_code'] && !empty    ($_SESSION['chapcha_code'] ) ) {
$youremail = 'info@example.com';
$fromsubject = 'www.example.co.uk';
$title = $_POST['title'];
$fname = $_POST['fname'];
$mail = $_POST['mail'];
$phone = $_POST['phone']; 
$subject = $_POST['subject']; 
$message = $_POST['message']; 
$to = $youremail; 
$mailsubject = 'Message from Website'.$fromsubject.' Contact Page';
$body = $fromsubject.'
The person that contacted you is:  '.$fname.'
 Phone Number: '.$phone.'
 E-mail: '.$mail.'
 Subject: '.$subject.'
 Message: 
 '.$message.'

|---------END MESSAGE----------|'; 
echo "Thank you for your message. I will contact you shortly if needed.<br/>Go to <a     href='/index.html'>Home Page</a>"; 
                            mail($to, $subject,     $body);
    unset($_SESSION['chapcha_code']);
} else {
    echo 'Sorry, you have provided an invalid security code';
}
} else { 
echo "You must write a message. </br> Please go to <a href='/contact.html'>Contact Page</a>"; 
}
?> 

您需要一些标头,以便发件人地址是用户邮件。

另请参阅邮件文档

试试这个

$headers = "From: $mail'r'n";
$headers .= "Reply-To: $mail'r'n";

mail($to, $subject,$body,$headers);
相关文章: