Robin
Robin

Reputation: 41

How can "reply-to" be added to the email we get from our website PHP form?

More stringent DMARC policy means we are not getting emails from customers who use our online form if they enter a yahoo or AOL email address.

I think this is because the PHP form generates an email that is sent from our website server but that has the customers own email address as 'from'. When this 'from' email is a yahoo email it triggers our receiving email account to block it. (We use gmail to read and reply to emails.)

Therefore I am trying to work out how to modify the PHP form to put the customers email address as 'reply-to' and our own server email address as 'from' in the email that the PHP form on our server sends us. I want to be able to click 'reply' in gmail and be able to email the customer straight back.

It would also be nice to have the customers name in the subject or the gmail from field to make the emails we receive from the form more readable, but this is of far less concern.

Here is the content of the php file as it currently is.

<?php
$to         ="[email protected]";
$name       = ($_POST['name']);
$email      = ($_POST['email']);
$phone      = ($_POST['phone']);
$enquiry    = ($_POST['enquiry']);
$where      = ($_POST['where']);
$sub        = "Enquiry from the Futonz Website!";
$headers .= "From: $name <$email>\n";  
$headers .= "Content-Type: text/plain; charset=iso-8859-1\n";
$mes       = "".$sub."

Name: ".$name."
Email: ".$email."
Phone: ".$phone." 

Message: ".$enquiry."

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();
}
?>

Reading other people's advice, I have tried replacing the first $headers with the following:

$headers = 'From: '[email protected]."\r\n" .
        'Reply-To: '.$email."\r\n";

This did not work. The browser just goes to a blank screen.

I have also tried adding another $headers line below the first like this:

$headers .= "From: $name <[email protected]>\n";
$headers .= "Reply-to: $name <$email>\n";  

This does appear in gmail as having the customer's email as 'reply to'. However, when 'reply' is clicked on in Gmail it puts [email protected] as the recipient instead!

To reply to TheGreenKey's comment below, when using the code:

$headers .= "From: $name <[email protected]>\n";
$headers .= "Reply-to: $name <$email>\n";  

then the following results:

Delivered-To: [email protected]
Received: by 10.52.238.130 with SMTP id vk2csp258969vdc;
        Fri, 13 Feb 2015 18:18:11 -0800 (PST)
X-Received: by 10.140.19.14 with SMTP id 14mr30541534qgg.37.1423880290937;
        Fri, 13 Feb 2015 18:18:10 -0800 (PST)
Return-Path: <[email protected]>
Received: from zeke.hosts.net.nz (zeke.hosts.net.nz. [210.48.108.243])
        by mx.google.com with ESMTPS id q137si1269163qha.85.2015.02.13.18.18.09
        for <[email protected]>
        (version=TLSv1 cipher=RC4-SHA bits=128/128);
        Fri, 13 Feb 2015 18:18:10 -0800 (PST)
Received-SPF: none (google.com: [email protected] does not designate permitted sender hosts) client-ip=210.48.108.243;
Authentication-Results: mx.google.com;
       spf=none (google.com: [email protected] does not designate permitted sender hosts) [email protected]
Received: from futonz.co.nz (localhost.localdomain [127.0.0.1])
    by zeke.hosts.net.nz (8.13.8/8.13.8) with ESMTP id t1E2Hxjm006900
    for <[email protected]>; Sat, 14 Feb 2015 15:17:59 +1300
Received: (from futonz@localhost)
    by futonz.co.nz (8.13.8/8.13.8/Submit) id t1E2Hwf6006899;
    Sat, 14 Feb 2015 15:17:58 +1300
Date: Sat, 14 Feb 2015 15:17:58 +1300
Message-Id: <[email protected]>
To: [email protected]
Subject: Enquiry from the Futonz Website!
From: Robin test <[email protected]>
Reply-to: Robin test <[email protected]>
Content-Type: text/plain; charset=iso-8859-1


Enquiry from the Futonz Website!

Name: Robin test
Email: [email protected]
Phone: 09 

Message: 

I found Futonz by: 

Please tell me how to modify the php form so that the customer's email address appears when 'reply' is clicked on in gmail.

Upvotes: 2

Views: 2879

Answers (2)

Robin
Robin

Reputation: 41

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       = "[email protected]";
$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

Upvotes: 2

parveen
parveen

Reputation: 577

$headers = "From: " . strip_tags($_POST['email']) . "\r\n";
$headers .= "Reply-To: [email protected]\r\n";
$headers .= "CC: [email protected]\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

Upvotes: 1

Related Questions