Using the SMTP Transport
The SMTP Transport is easy to use. Most configuration options can be set with the constructor.
To use the SMTP Transport you need to know which SMTP server your code needs to connect to. Ask your web host if you're not sure. Lots of people ask me who to connect to – I really can't answer that since it's a setting that's extremely specific to your hosting environment.
To use the SMTP Transport:
- Call Swift_SmtpTransport::newInstance() with the SMTP server name and optionally with a port number (defaults to 25).
- Use the returned object to create the Mailer.
A connection to the SMTP server will be established upon the first call to send() or batchSend().
<?php
require_once 'lib/swift_required.php';
//Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25);
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
/*
It's also possible to use multiple method calls
$transport = Swift_SmtpTransport::newInstance()
->setHost('smtp.example.org')
->setPort(25)
;
*/
Parent topic: The SMTP Transport
Next topic: Encrypted SMTP