PHP回复错误 - 管理员电子邮件不是联系表单的发件人

时间:2012-08-14 11:59:04

标签: php

我有以下PHP联系表单,其中包含CAPTCHA代码以确保正确无误。但是,当我回复来自网站的电子邮件时,它会随机发送一封我认为是服务器管理员的电子邮件,但是,我希望它是发送表单的人员。下面是代码,你能否做到帮助我?

<?php session_start();
if(isset($_POST['Submit'])) {   if( $_SESSION['chapcha_code'] == $_POST['chapcha_code'] && !empty($_SESSION['chapcha_code'] ) ) {
$youremail = 'info@domain.com';
$fromsubject = 'www.domain.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); 

非常感谢

GS-计算机

1 个答案:

答案 0 :(得分:3)

请替换

mail($to, $subject, $body);

使用您的代码

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

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