0

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('info@example.com', '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 = 'postmaster@example.com';
    $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 = 'postmaster@example.com';
    $this->mailer->DKIM_private = 'private.key';
    $this->mailer->setFrom('postmaster@example.com', '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:<postmaster@example.com>
2022-08-09 05:08:51 SERVER -> CLIENT: 250 OK
2022-08-09 05:08:51 CLIENT -> SERVER: RCPT TO:<webmaster@example.com>
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 <info@example.com>
2022-08-09 05:08:51 CLIENT -> SERVER: From: Postmaster <postmaster@example.com>
2022-08-09 05:08:51 CLIENT -> SERVER: Reply-To: Customer <customer@example.com>
2022-08-09 05:08:51 CLIENT -> SERVER: Subject: Message from Customer
2022-08-09 05:08:51 CLIENT -> SERVER: Message-ID: <v94gh2938gh9203eihjvkosashfah@example.com>
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>customer@example.com</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
chillywilly
  • 405
  • 3
  • 11
  • 3
    Can you show the headers of a message as it is sent (set `SMTPDebug = 2`) and after it is received? – Synchro Aug 08 '22 at 18:49
  • @Synchro Thanks for your reply! I have added the headers (anonymized). Hopefully they are helpful. – chillywilly Aug 09 '22 at 05:20
  • 1
    OK, so that shows that the message *is* sent with the requested reply-to address. Now you need to inspect it in Apple Mail to see whether it appears any different in there. Bear in mind that it will not say that it is from that address, but when you reply, it should use the reply-to address as the to address for a new message, just to be clear! – Synchro Aug 09 '22 at 16:33
  • Detailed email headers are not available for Apple Mail on iOS, but I checked the headers of the email I received at Gmail. I see the reply-to address there as well. Since the code looks good to you and the headers received by the email client also look good, is it safe to say that we can't fix this on our end, and I should report this as a bug to Apple? – chillywilly Aug 09 '22 at 18:35
  • 1
    Yes, though I'm surprised at this as I've never seen that happen. Apple Mail on macOS certainly doesn't do it. – Synchro Aug 09 '22 at 21:54
  • 1
    I spoke with Apple. They said they aren't aware of any bugs in Apple Mail related to "reply to." They also highlighted that the current iOS version is 15.6. Perhaps if my client updates his iPhone the problem will go away. We shall see... thanks for your feedback. If he updates his phone, I'll let you know if it solves the problem. – chillywilly Aug 10 '22 at 05:24

0 Answers0