Reply to sender - PHP email
you need to set the headers
to be able to pass the sender email:
fx:
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
so your code will look something like this:$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "adamgoredesign@gmail.com";
$headers = 'From: '.$email."\r\n" .
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
header('Location: contact_thankyou.html');
Note: I never tested myself, I normally use smtp.mail class to do all this for me, since it is more easy, clean... just check it out...then it will look something like this:
<?php
require 'class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'jswan'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->AddAddress('josh@example.net', 'Josh Adams'); // Add a recipient
$mail->AddAddress('ellen@example.com'); // Name is optional
$mail->AddReplyTo('info@example.com', 'Information');
$mail->AddCC('cc@example.com');
$mail->AddBCC('bcc@example.com');
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
reply-to address in php contact form
Try changing this part of your code :
$subject = "Contact Form: $name";
$message = "$message";
$headers = 'From: myemail@my_domain.com' . "\r\n" .
'Reply-To: $email' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
To this :$subject = "Contact Form: $name";
$message = "$message";
$headers = 'From: myemail@my_domain.com' . "\r\n" .
'Reply-To: ' . $email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
Basically take out the $email from inside the single quote and append it to that string Replying to an email with PHPmailer
It's quite reasonable to have every message in a thread using a different subject line, so threading is only dependent on the subject line as a last-resort fallback if you're doing everything else wrong. It's actually quite annoying when clients do this as you end up with unrelated messages that happen to have the same subject grouped together.
Threading and replies are implemented using the References
and In-Reply-To
headers as defined in RFC2822. Read this guide for a thorough description of how to do threading reliably.
The short version is this, for the first reply to a message:
$mail->addCustomHeader('In-Reply-To', $message_id);
$mail->addCustomHeader('References', $message_id);
It gets more complex if the original message is just the latest in a long thread, but it uses the same headers - read the spec and the guide for more info.Make sure your message ID is correctly formatted - it should be surrounded by <>
, like <d7751ea969c01cda464ebf2de2fe64e6@example.org>
.
You don't need to do anything to the subject line - though it's common to prepend Re:
, it's not necessary for the linkage to work, and it also varies across languages, so it's not something you can rely on.
how to reply to sender email using php contact form
First make headers
$headers = "From: $from\r\nReply-to: $email";
Than fix calling of mail function to bemail ($to, $subject, $body, $headers)
Didn't tried it from times when it was PHP 4 but it will probably work as you expected...Addition:
I just checked on php.net... go to this url http://php.net/manual/en/function.mail.php and check "Example #2 Sending mail with extra headers."
My php form doesn't allow me to reply to the sender
When you reply to an email, normally your email program will populate the "to" field of the reply email.
Normally it populates this with the value in the "from" field of the original email. However, this can be overridden if the headers of the original email contain a valid "reply-to" value. If that is set correctly, the email program will use the email address in the "reply-to" field as the "to" field of the reply.
However in your case this isn't happening because you have a logical error in the code:
'Reply-To: ' . $headers
makes no sense, because $headers
doesn't exist at that time. You've written this inside the statement $headers =
...so headers is only just being defined. And even if it was defined at this moment, it wouldn't contain what's needed for a reply-to field.You need to include an email address in that header. You could simply hard-code it, but it sounds like you want it to be set to the email address that the user submits in the form. You didn't say what that field is called, but presumably it comes from the POST values, therefore something like this would make sense:
'Reply-To: ' . $_POST["email"]
Just change the bit inside the [ ]
depending on the exact name of the email field in your form.(You might also want to check out this answer which contains equivalent code to send the mail via PHPMailer, which is easier to use and more robust than mail()
- I highly recommend it.)
How can reply-to be added to the email we get from our website PHP form?
Here is the code I used to fix both the DMARC authentication problem and the correct 'reply to' email address coming up in gmail.
<?php
$to = "info@futonz.co.nz";
$name = ($_POST['name']);
$email = ($_POST['email']);
$phone = ($_POST['phone']);
$enquiry = ($_POST['enquiry']);
$where = ($_POST['where']);
$sub = "".$name."'s enquiry from the Futonz Website!";
$headers .= "MIME-Version:1.0\n";
$headers .= "Content-type: text/plain; charset=utf-8\n";
$headers .= "X-Mailer: $DOMAIN\n";
$headers .= "X-MSMail-Priority: normal\n";
$headers .= "Return-Path: ".$email."\r\n";
$headers .= "From: ".$from."\r\n";
$headers .= "Reply-To: ".$email."\r\n";
$mes = "".$sub."\r\n\n";
$mes .= "Name: ".$name."\r\n";
$mes .= "Email: ".$email."\r\n";
$mes .= "Phone: ".$phone."\r\n\n";
$mes .= "Message: ".$enquiry."\r\n\n";
$mes .= "I found Futonz by: ".$where."";
if(empty($name) || empty($email)) {
header("Location:required-fields.html");
}
elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
header("Location:invalid-email.html");
}
else {
mail($to, $sub, $mes, $headers);
header("Location:contact-thanks.html");
exit();
}
?>
Thank you to those who tried to help here :)This link may be of interest to people trying to fix yahoo DMARC problems:
https://help.yahoo.com/kb/mail/SLN24016.html
Related Topics
The Behaviour of the or Operator in PHP
How to Get the Absolute Path to the Public_HTML Folder
What Are Available Solutions of a Browser/Mobile Phone Detection
Denormalize Nested Structure in Objects with Symfony 2 Serializer
Laravel Customized Session.Lifetime at User Level
Setting Up PHPmailer with Office365 Smtp
Use MySQL_Fetch_Array() with Foreach() Instead of While()
Prevent Back Button After Logout
Png Transparency Resize with Simpleimage.PHP Class
What Is the Js Equivalent to the PHP Function Number_Format
Upload Progress Using Pure PHP/Ajax
Disable Doctrine 2 Lazy Loading When Using Jms Serializer
Are There Any PHP Docblock Parser Tools Available
When Do/Should I Use _Construct(), _Get(), _Set(), and _Call() in PHP
Mail Not Sending with PHPmailer Over Ssl Using Smtp
Find All Second Level Keys in Multi-Dimensional Array in PHP
Add a Custom Checkbox in Woocommerce Checkout Which Value Shows in Admin Edit Order