3

I want to setup a similar message structure as in github, where a user can either respond by email or logging into his account.

Github appears to have a unique-id in the reply-to field:

reply+i-39945717-887b26ec5b3de79d00dec7ef29ad308795b85685-6876349@reply.github.com

Is it possible to add a unique ID to the "Reply-to"-header with swift-mailer?

How would the mail server be able to work with this?

xfscrypt
  • 16
  • 5
  • 28
  • 59

2 Answers2

4

For responding to using email, you can use In-Reply-To alongside Reply-To.

For this purpose you can use this StackOverFlow answer: Correct headers for replying and forwarding emails
In summary you need to track your message using its ID and its id is stored in In-Reply-To and this is the way you can set it:

$headers = $message->getHeaders();

$headers->addTextHeader('In-Reply-To', $previousEmail->getHeaders()->getMessageId());
Community
  • 1
  • 1
Mohamad Eghlima
  • 970
  • 10
  • 23
2

Well, why not? Setting Reply-to with SwiftMailer is quite easy:

<?php

$message = new \Swift_Message();
$message->setReplyTo(sprintf(
    'reply+%s@your-domain.com',
    uniqid()
));

The uniquid() call is just for example. In real-life code you'd persist the entity ID beforehand (e.g. when you save it), and retrieve it from your model object later.

However, you'll need to set up a mail checker that would receive your incoming mail, parse it and transform into CRUD operations on your database.

kix
  • 3,290
  • 27
  • 39
  • the last part is actually the thing I am stuck with. Isn't The reply-to field expecting an email address? – xfscrypt Aug 12 '14 at 11:30
  • @apfz, well, isn't it a valid email address? The `+` sign is allowed there, and the mail should be received by the alias without the `+` sign and the suffix. – kix Aug 12 '14 at 12:22
  • did not know it was allowed. thanks for this. However PHP is not fetching the value after (and including) the plus sign (it just trims it), but for that I will post another question. – xfscrypt Aug 13 '14 at 04:03