PHP SMTP send mail with SwiftMailer

PHP send mail with SwiftMailer Sample Code

Note: your_domain_name.com is your actual domain name. name is your actual email address name. your_email_password is your actual email password.
 
<?php

require_once 'swift_required.php';

// Create the Transport
$transport = Swift_SmtpTransport::newInstance('mail.your_domain_name.com', 587)
->setUsername('name@your_domain_name.com') 
->setPassword('your_email_password')
;

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

// Create a message
$message = Swift_Message::newInstance('Message Using Swiftmailer')
->setFrom(array('name@your_domain_name.com' => 'From Name'))
->setTo(array('name@your_domain_name.com' => 'To Name'))
->setBody('Here is the message itself')
;

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

// Print to screen
print("Message Sent");

?>
 

Add Feedback