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

时间:2012-08-14 10:37:13

标签: php

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

<?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>"; 
}
?> 

1 个答案:

答案 0 :(得分:0)

您需要一些标题,因此起始地址是用户邮件。

另请参阅mail docs

试试这个

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


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