English support > vLIB examples
Creating a mail with "Swift Mailer"
(1/1)
ClausVB:
Tested with version "Swift-4.0.5.tar.gz" ...
--- Code: ---<?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(localhost, 25);
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Send the message
$result = $mailer->send($message);
echo > . $result . <;
?>
--- End code ---
--- Code: ---<?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(localhost, 25);
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Send the message
$result = $mailer->send($message);
echo > . $result . <;
?>
--- End code ---
Navigation
[0] Message Index
Go to full version