Created
May 27, 2019 15:14
-
-
Save rahman541/9740a35436b8e72b3f87e33ec1ba543e to your computer and use it in GitHub Desktop.
SMTP Gmail sending mail.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// REF: https://swiftmailer.symfony.com/docs/introduction.html | |
// composer require "swiftmailer/swiftmailer:^6.0" | |
require_once './vendor/autoload.php'; | |
$MAIL_HOST = 'smtp.gmail.com'; | |
$MAIL_PORT = '465'; | |
$MAIL_USERNAME = '[email protected]'; | |
$MAIL_PASSWORD = 'mypwd'; | |
$MAIL_ENCRYPTION = 'ssl'; | |
$RECEIVER_MAIL = '[email protected]'; | |
// Create the Transport | |
$transport = (new Swift_SmtpTransport($MAIL_HOST, $MAIL_PORT, $MAIL_ENCRYPTION)) | |
->setUsername($MAIL_USERNAME) | |
->setPassword($MAIL_PASSWORD); | |
// Create the Mailer using your created Transport | |
$mailer = new Swift_Mailer($transport); | |
// Create a message | |
$message = (new Swift_Message('Wonderful Subject')) | |
->setFrom(['[email protected]' => 'John Doe']) | |
->setTo([$RECEIVER_MAIL => 'A name']) | |
->setBody('Here is the message itself'); | |
// Send the message | |
$result = $mailer->send($message); | |
echo $result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment