Composer Dependency Use
Project Structure
index.php
<?php
require __DIR__ . '/vendor/autoload.php';
$transport = Swift_SmtpTransport::newInstance('smtp.vianet.com.np');
/*
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465,'ssl')//465 or 487
->setUsername('mailAddress@gmail.com')
->setPassword('*********');
*/
// Create the message
$message = Swift_Message::newInstance();
//Give the message a subject
$message->setSubject('Your subject')
->setFrom('fromMailAddress@gmail.com','Your bank')
->setTo('toMailAddress@gmail.com')
->setBody('Here is the message sent with swiftmailer')
->attach(Swift_Attachment::fromPath('images/foto.png'))
->addPart('<q>Here is the message sent with swiftmailer</q>', 'text/html');
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
//Send the message
$result = $mailer->send($message);
if ($result) {
echo "Email sent successfully";
} else {
echo "Email failed to send";
}
?>
Output:
Source: http://swiftmailer.org/
0 comments:
Post a Comment