Return to Snippet

Revision: 62424
at February 21, 2013 22:56 by draciP


Updated Code
<?php

$local	= true;

// Create the Mailer using any Transport
$mailer = Swift_Mailer::newInstance(
	Swift_SmtpTransport::newInstance('smtp.example.org', 25)
);

// Create the Message
$message = Swift_Message::newInstance()
		->setSubject('My subject')
		->setFrom(array('[email protected]' => 'John Doe'))
		->setTo('[email protected]')
		->setCc('[email protected]')
		->setBcc('[email protected]')
		->setBody('My content');

if( $local ) {
	// Register the RedirectPlugin, only in local development environment
	$mailer->registerPlugin(new Swift_Plugins_RedirectingPlugin('[email protected]'));
	// and then, no email will be sent to [email protected] or [email protected] or [email protected]
}

// Send the Message
$mailer->send($message);

Revision: 62423
at February 21, 2013 22:46 by draciP


Initial Code
$local	= true;

// Create the Mailer using any Transport
$mailer = Swift_Mailer::newInstance(
	Swift_SmtpTransport::newInstance('smtp.example.org', 25)
);

// Create the Message
$message = Swift_Message::newInstance()
		->setSubject('My subject')
		->setFrom(array('[email protected]' => 'John Doe'))
		->setTo('[email protected]')
		->setCc('[email protected]')
		->setBcc('[email protected]')
		->setBody('My content');

if( $local ) {
	// Register the RedirectPlugin, only in local development environment
	$mailer->registerPlugin(new Swift_Plugins_RedirectingPlugin('[email protected]'));
}

// Send the Message
$mailer->send($message);

Initial URL
http://swiftmailer.org/docs/introduction.html

Initial Description
This is a little snippet to prevent sending emails to customers, in a local development environment, with Swiftmailer.
I didn't find any documentation about the RedirectPlugin, so I made this example.
Please refer to the official documentation to install Swiftmailer.

Initial Title
Sending emails in local development environment with Swiftmailer

Initial Tags

                                

Initial Language
PHP