Author Topic: Creating a mail with "Swift Mailer"  (Read 841 times)

0 Members and 1 Guest are viewing this topic.

Offline ClausVB

  • Administrator
  • Hero Member
  • *****
  • Posts: 566
    • Homepage: clausvb.de
Creating a mail with "Swift Mailer"
on: Mon, 26. October 2009 - 15:54:20
Tested with version "Swift-4.0.5.tar.gz" ...

Code: [Select]
<?php

require_once $_SERVER[DOCUMENT_ROOT] . /swift/swift_required.php;

// Create the message
$message Swift_Message::newInstance()
  
// Give the message a subject
  
->setSubject(Subject and timestamp:  date(Y-m-d H:i:s))

  
// Set the From address with an associative array
  
->setFrom(array([email protected] => from))

  
// Set the To addresses with an associative array
  
->setTo(array([email protected] => to))

  
// Give it a body
  
->setBody(Here is the message itself)
;

// Create the Transport
$transport Swift_SmtpTransport::newInstance(localhost25);

// Create the Mailer using your created Transport
$mailer Swift_Mailer::newInstance($transport);

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

echo 
&gt; $result &lt;;

?>

Code: [Select]
<?php

require_once $_SERVER[DOCUMENT_ROOT] . /swift/swift_required.php;

// Create the message
$message Swift_Message::newInstance();

$message->setSubject(Subject and timestamp:  date(Y-m-d H:i:s));
$message->setFrom(array([email protected] => from));
$message->setTo(array([email protected] => to));
$message->setBody(<h1>Caption: HTML mail</h1> My <em>amazing</em> <strong>body</strong>text/html);

// Create the Transport
$transport Swift_SmtpTransport::newInstance(localhost25);

// Create the Mailer using your created Transport
$mailer Swift_Mailer::newInstance($transport);

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

echo 
&gt; $result &lt;;

?>