Reply-To Header (SwiftMailer 3.3)

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
hknight
Forum Newbie
Posts: 13
Joined: Wed Aug 13, 2008 2:48 pm

Reply-To Header (SwiftMailer 3.3)

Post by hknight »

How can I add a Reply-To header?

I am using SwiftMailer 3.3.

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));
$swift->send($message, "example@gmail.com", new Swift_Address("example@gmail.com", "Example Sender"));
echo 'Sent!';
 
?>
 
lkjhaskdhjfla
Forum Newbie
Posts: 1
Joined: Mon Apr 08, 2013 4:53 pm

Re: Reply-To Header (SwiftMailer 3.3)

Post by lkjhaskdhjfla »

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!';
 
?>
 
Post Reply