I created a form submission that works. I get an email from ipg.blahblah@blahblah.com when someone fills out the form and submits it to me. Is there a way to change the From field in the email to be the visitor's email?
An example, Henry fills out my form and writes his email as henry@gmail.com and submits it to me. I'll get an email from ipg.blahblah@blahblah.com, is there a way to change ipg.blahblah@blahblah.com to henry@gmail.com?
I want to make it easier for me to just reply back to the email instead of creating a new email and replying back to Henry. I'm not sure if I can change it in my mail handler. Any pointers? I'll attach my mail handler code below.
<?php
if(isset($_POST['submit'])){
$url = 'Hidden';
$privatekey = "Hidden";
$response = file_get_contents($url."?secret=".$privatekey."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']);
$data = json_decode($response);
if(isset($data->success) AND $data->success==true){
//mail handler code
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$msg=$_POST['msg'];
$port = '25';
$to='Hidden';
$message="Form Submission: ".$name;
$headers="Name: ".$name."
"."From: ".$email. "
". "Phone:".$phone."
". "Wrote the following: "."
".$msg;
if(mail($to, $message, $headers)){
header('Hidden');
}
}
}else{
header('Hidden');
}
}
?>
What Magnus said. Look at the contact form example provided with PHPMailer for the right way to do it. Many email providers (for example gmail) will not let you set the from address at all, and doing so will lead to SPF failures as it’s forgery. Use your own address as the from address, and put the submitters address in a reply-to.