VERP support
Posted: Tue Mar 04, 2008 1:51 pm
What is the status of VERP support in Swift Mailer?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$message->headers->set('Sender', $something);Code: Select all
<?php
// Require Swift Mailer
require_once('./includes/lib/swift_required.php');
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('localhost', 25);
// Create the Mailer
$mailer = Swift_Mailer::newInstance($transport);
// Recipients
$rcpt_array = array('user@example.com');
$bounce_id_array = array('user@example.com' => 'verp-id');
// Create the message
$message = Swift_Message::newInstance()
->setSubject('Subject')
->setFrom(array('webmaster@example.com' => 'Example.com'))
->setTo($rcpt_array)
->setBody('Testing VERP plugin')
;
class Swift_Plugins_ReturnPathPlugin
implements Swift_Events_SendListener
{
public function beforeSendPerformed(Swift_Events_SendEvent $evt)
{
// Reset return path for all users
$newReturnPath = '';
$message = $evt->getMessage();
$rcpt_array = $message->getTo();
if (count($rcpt_array) == 1)
{
$rcpt_email_keys = array_keys($rcpt_array);
$rcpt_email = array_pop($rcpt_email_keys);
if (array_key_exists($rcpt_email, $GLOBALS['bounce_id_array']))
$newReturnPath = 'b-' . $GLOBALS['bounce_id_array'][$rcpt_email] . '@example.com';
}
$message->setReturnPath($newReturnPath);
$message->setSubject('New subject');
}
public function sendPerformed(Swift_Events_SendEvent $evt)
{
}
}
$returnPath = new Swift_Plugins_ReturnPathPlugin();
$mailer->registerPlugin($returnPath);
$sent = $mailer->batchSend($message);
echo $sent;
Code: Select all
if (!$reversePath = $this->_getReversePath($message))
{
throw new Swift_TransportException(
'Cannot send message without a sender address'
);
}