Search code examples
phpphp-ews

PHP-EWS (GarethP) setReplyTo


Using PHP-EWS (GarethP), I am attempting to setReplyTo like this:

use garethp\ews\API\Type;
use garethp\ews\MailAPI;

$api = MailAPI::withUsernameAndPassword("host", "username", "password");
$message = new Type\MessageType();
$message->setSubject("Some Subject");
$message->setBody("Test Email");
$message->setToRecipients("[email protected]");
$message->setReplyTo("[email protected]"); // <-- this is the 'ReplyTo' address I want to set.
$api->sendMail($message);

But this does not have any affect, and the recipient is then replying to the sender/from address.

The Api callback shows:

'replyTo' => NULL,

Any ideas on how solve?


Solution

  • Ah, I figured it out. For anyone else experiencing a similar issue, here is what I found.

    Within the MessageType.php file, the addReplyTo and setReplyTo functions are missing.

    Adding these in the same way as the setToRecipients, setCcRecipients and setBccRecipients functions solves the problem:

    public function addReplyTo($recipient)
        {
            return parent::addReplyTo(ensureIsMailbox($recipient));
        }
    public function setReplyTo($recipients)
        {
            $this->replyTo = [ ];
            $recipients = ensureIsArray($recipients);
    
            foreach ($recipients as $recipient) {
                $this->addReplyTo($recipient);
            }
    
            return $this;
        }