Email not being sent with Swift Mailer using Gmail SMTP
How to use Swift Mailer Using Gmail SMTP
Try this code like this:
<?php
require_once 'lib/swift_required.php';
try
{
echo '<pre>';
//Generating the Email Content
$message = Swift_Message::newInstance()
->setFrom(array('myemail@gmail.com' => 'No Reply'))
->setTo(array('recipient@gmail.com' => 'Recipient'))
->setSubject('Test Email')
->setBody("This is a Test Email to check SwiftMailer.");
// Create the Mail Transport Configuration
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587, 'tls')
->setUsername('myemail@gmail.com')
->setPassword('appPassword')
->setStreamOptions(array(
'ssl' => array(
'allow_self_signed' => true,
'verify_peer' => false)));
//local domain sending
$transport->setLocalDomain('[127.0.0.1]');
$mailer = Swift_Mailer::newInstance($transport);
//Send the email
$sentFlag = $mailer->send($message);
}
catch (Exception $e)
{
echo $e->getMessage();
}
?>
Hope it helps
Swiftmailer config : send mail using gmail
Looks like your live server is missing OpenSSL
, so you need to enable it in order to get secure connections working (i.e. enable the php_openssl
module). Also check this question.
Related Topics
Generating Cryptographically Secure Tokens
How to Emulate a Get Request Exactly Like a Web Browser
I Cannot Get My Login Form to Connect Interact Properly With MySQL Database
How to Best Store User Information and User Login and Password
Switch PHP Versions on Commandline Ubuntu 16.04
Storing and Displaying Unicode String (हिन्दी) Using PHP and MySQL
PHP: How to Get File Creation Date
How to Set the Default Value of a Timestamp Column to the Current Timestamp With Laravel Migrations
Show Image Using File_Get_Contents
PHP Expression ≪≪≪Eob
Return Index of Highest Value in an Array
Decode Gzipped Web Page Retrieved Via Curl in PHP
How to Write to the Console in PHP
Laravel-5 'Like' Equivalent (Eloquent)
Match A^N B^N C^N (E.G. "Aaabbbccc") Using Regular Expressions (Pcre)