Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replyto email is sometimes ignored by Apple Mail #2743

Closed
greatgraphicdesign opened this issue Aug 8, 2022 · 1 comment
Closed

replyto email is sometimes ignored by Apple Mail #2743

greatgraphicdesign opened this issue Aug 8, 2022 · 1 comment

Comments

@greatgraphicdesign
Copy link

greatgraphicdesign commented Aug 8, 2022

My client uses Apple Mail on his iPhone 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);
    }
  }
}
@Synchro
Copy link
Member

Synchro commented Aug 8, 2022

This isn't a PHPMailer bug, so I'll close it here, but I've commented on your question on Stack Overflow.

@Synchro Synchro closed this as completed Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants