GS-Computers
GS-Computers

Reputation: 1

PHP reply-to error - comes with admin email not sender of contact form

I have the below PHP contact form that has a CAPTCHA code to ensure is correct. However, when I reply to the email from the website it puts a random email which i believe is the server admin, however, I want it to be the persons email who sent the form in. below is the code, could you possibly be able to help me?

<?php session_start();
if(isset($_POST['Submit'])) {   if( $_SESSION['chapcha_code'] == $_POST['chapcha_code'] && !empty($_SESSION['chapcha_code'] ) ) {
$youremail = '[email protected]';
$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>"; 
}
?> 

I have been told to put the below into the code, but where do I put it?

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

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

Many thanks

GS-Computers

Upvotes: 0

Views: 851

Answers (1)

Jerzy Zawadzki
Jerzy Zawadzki

Reputation: 1985

Please replace

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

with your code

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

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

Upvotes: 3

Related Questions