My client uses Apple Mail on his iPhone (iPhone 8,
iOS 13.3) to respond to incoming website emails where we have a PHPMailer contact form. About half the time when he replies, the "replyto" email address is ignored by Mail and the "from" address is used instead. Since we're using the postmaster address in the "from" to improve email deliverability, he ends up replying to Postmaster instead of the customer. I use Gmail, and I've never experienced this problem with my own forms using the same type of code so this seems like an issue with Apple Mail. Nevertheless, I thought I'd ask if there was something I could do to solve this. Maybe there's something wrong with my code?
validation:
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['contact'])) {
// validation code where $email and $name are defined as submitted and $error is true if validation fails
if ($error === false) {
$email_package = new Email();
// assemble HTML message to be emailed
$email_html = "<html email>";
$email_package->addReplyTo($email, $name);
$email_package->addRecipient('[email protected]', 'Customer Service');
$email_package->setSubject('Message from Customer');
$email_package->isHTML(true);
$email_package->setBodyHTML($email_html);
$email_package->send();
if($email_package->mailSuccess === false) {
error_log("FAIL: " . $email_package->mailError);
}
}
}
email script:
date_default_timezone_set('America/Los_Angeles');
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
require 'PHPMailer/Exception.php';
require 'PHPMailer/PHPMailer.php';
require 'PHPMailer/SMTP.php';
class Email {
private $mailer;
var $mailSuccess = false;
var $mailError = '';
function __construct() {
$this->mailer = new PHPMailer(true);
$this->mailer->isSMTP();
$this->mailer->Host = 'mail.example.com';
$this->mailer->SMTPAuth = true;
$this->mailer->Username = '[email protected]';
$this->mailer->Password = 'password';
$this->mailer->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$this->mailer->Port = 465;
$this->mailer->CharSet = PHPMailer::CHARSET_UTF8;
$this->mailer->DKIM_domain = $domain;
$this->mailer->DKIM_selector = 'selector';
$this->mailer->DKIM_identity = '[email protected]';
$this->mailer->DKIM_private = 'private.key';
$this->mailer->setFrom('[email protected]', 'Postmaster');
}
public function addReplyTo($address, $name = '') {
return $this->mailer->addReplyTo($address, $name);
}
public function addRecipient($address, $name = '') {
return $this->mailer->addAddress($address, $name);
}
public function setSubject($subject) {
$this->mailer->Subject = $subject;
}
public function isHTML($bool) {
$this->mailer->isHTML($bool);
}
public function setBodyHTML($email_html) {
$this->mailer->Body = $email_html;
}
public function setBodyText($email_text) {
$this->mailer->AltBody = $email_text;
}
public function send() {
try {
$this->mailer->send();
$this->mailSuccess = true;
} catch (Exception $e) {
$this->mailError = $e->errorMessage();
error_log('PHPMailer Error: ' . $this->mailError);
} catch (\Exception $e) {
$this->mailError = $e->getMessage();
error_log('PHPMailer Error: ' . $this->mailError);
}
}
}
Anonymized email headers with SMTPDebug = 2:
2022-08-09 05:08:51 SERVER -> CLIENT: 220-host1234.webhost.com ESMTP Exim 4.95 #2 Tue, 09 Aug 2022 00:08:51 -0500 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
2022-08-09 05:08:51 CLIENT -> SERVER: EHLO example.com
2022-08-09 05:08:51 SERVER -> CLIENT: 250-host1234.webhost.com Hello example.com [IP.AD.DRE.SS]250-SIZE 52428800250-8BITMIME250-PIPELINING250-PIPE_CONNECT250-AUTH PLAIN LOGIN250 HELP
2022-08-09 05:08:51 CLIENT -> SERVER: AUTH LOGIN
2022-08-09 05:08:51 SERVER -> CLIENT: 334 fifoahfoahskjs
2022-08-09 05:08:51 CLIENT -> SERVER: [credentials hidden]
2022-08-09 05:08:51 SERVER -> CLIENT: 334 gehjfakshfgsaj
2022-08-09 05:08:51 CLIENT -> SERVER: [credentials hidden]
2022-08-09 05:08:51 SERVER -> CLIENT: 235 Authentication succeeded
2022-08-09 05:08:51 CLIENT -> SERVER: MAIL FROM:<[email protected]>
2022-08-09 05:08:51 SERVER -> CLIENT: 250 OK
2022-08-09 05:08:51 CLIENT -> SERVER: RCPT TO:<[email protected]>
2022-08-09 05:08:51 SERVER -> CLIENT: 250 Accepted
2022-08-09 05:08:51 CLIENT -> SERVER: DATA
2022-08-09 05:08:51 SERVER -> CLIENT: 354 Enter message, ending with "." on a line by itself
2022-08-09 05:08:51 CLIENT -> SERVER: Date: Mon, 8 Aug 2022 22:08:51 -0700
2022-08-09 05:08:51 CLIENT -> SERVER: To: Customer Service <[email protected]>
2022-08-09 05:08:51 CLIENT -> SERVER: From: Postmaster <[email protected]>
2022-08-09 05:08:51 CLIENT -> SERVER: Reply-To: Customer <[email protected]>
2022-08-09 05:08:51 CLIENT -> SERVER: Subject: Message from Customer
2022-08-09 05:08:51 CLIENT -> SERVER: Message-ID: <[email protected]>
2022-08-09 05:08:51 CLIENT -> SERVER: X-Mailer: PHPMailer 6.6.3 (https://github.com/PHPMailer/PHPMailer)
2022-08-09 05:08:51 CLIENT -> SERVER: MIME-Version: 1.0
2022-08-09 05:08:51 CLIENT -> SERVER: Content-Type: text/html; charset=utf-8
2022-08-09 05:08:51 CLIENT -> SERVER:
2022-08-09 05:08:51 CLIENT -> SERVER: <html><body><p>This is a test with Debug set to 2.</p><h4 style='margin: 2em 0 0; border-left: 1px solid black; padding-left: 1em;'>Chilly Willy<br>[email protected]</h4></body></html>
2022-08-09 05:08:51 CLIENT -> SERVER:
2022-08-09 05:08:51 CLIENT -> SERVER: .
2022-08-09 05:08:51 SERVER -> CLIENT: 250 OK id=1oLHU3-002bvb-Vb
2022-08-09 05:08:51 CLIENT -> SERVER: QUIT
2022-08-09 05:08:52 SERVER -> CLIENT: 221 host1234.webhost.com closing connection
My Answer:
Based on the code and email headers provided, it seems like everything is set up correctly in terms of adding the "Reply-To" header in the email. The issue might be related to how Apple Mail handles the "Reply-To" header.
One thing you can try is to explicitly set the "From" header in the email script to the customer's email address instead of the postmaster address. This way, even if Apple Mail ignores the "Reply-To" header, the reply will still go to the customer's email address.
You can modify the `setFrom` method in the `Email` class to accept the customer's email address as a parameter and use that in the email headers. Here's an example:
php
public function setFrom($address, $name = '') {
$this->mailer->setFrom($address, $name);
}
Then, in your main script, before calling `send()`, you can set the "From" header to the customer's email address like this:
php
$email_package->setFrom($email, $name);
This way, even if Apple Mail ignores the "Reply-To" header, the reply will still go to the customer's email address.
Additionally, you can try testing the email functionality with a different email client or service to see if the issue persists only with Apple Mail. This can help determine if the problem is specific to Apple Mail or if there is an issue with the code.
If the issue continues to persist, you may need to further investigate how Apple Mail handles email headers and possibly reach out to Apple support for assistance.
Rate this post
3 of 5 based on 7741 votesComments