I created this account solely to reply to this message since it's currently ranking very high in search results for "swift mailer reply to header."
Here is the documentation:
http://swiftmailer.org/docs/
In it, I could not find an example of adding a Reply-To header. So I used the source.
You are looking for this method: Swift_Mime_SimpleMessage::addReplyTo(). Swift_Message extends that class.
So, adding that to the code in the OP:
hknight wrote:
Code: Select all
<?php
require_once "Swift.php";
require_once "Swift/Connection/Sendmail.php";
$swift = new Swift(new Swift_Connection_Sendmail(Swift_Connection_Sendmail::AUTO_DETECT));
$mg = "This is the message\nHello123";
$message =& new Swift_Message('Subject Line');
$message->attach(new Swift_Message_Part($mg));
// HERE COMES THE REPLY-TO !!!
$message->addReplyTo('jdoe@example.com', 'John Doe');
$swift->send($message, "example@gmail.com", new Swift_Address("example@gmail.com", "Example Sender"));
echo 'Sent!';
?>