Sending a HTML Email

First you need to include the “swift_required.php” file, then you create an instance of the Mailer using any of the Transports (probably Swift_SmtpTransport, Swift_SendmailTransport or Swift_MailTransport). Then you create a a message, specifying “text/html” as a content type and send it with the Mailer.

<?php
 
//Include this needed file
require_once '/path/to/swift/lib/swift_required.php';
 
//Start the mailer
$mailer = new Swift_Mailer(new Swift_MailTransport());
 
//Create a message
$message = Swift_Message::newInstance('Your subject', 'Your Message', 'text/html')
  ->setFrom(array('your@address.tld' => 'Your Name'))
  ->setTo(array('someone@address.tld' => 'Person name'));
 
//Send it
$mailer->send($message);
 
v4/examples/html.txt · Last modified: 2008/05/22 05:48 by d11wtq
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki