trying to send mail using swift mailer, gmail smtp, php
GMail's SMTP requires encryption. Use:
Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl");
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.
Can not send mail with the gmail smtp and the swift mailer
You can fix the [Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?
by recompiling PHP using the --with-ssl[=DIR]
option.
In order to be able to do that, you have to install the OpenSSL libraries onto your server. Depending on your OS, you can do something like apt-get install openssl-dev
on Debian/Ubuntu, or yum install openssl-devel
on RedHat/CentOS/Fedora.
Alternatively, you can just download and compile the latest version of OpenSSL yourself and use that with PHP.
If you do not run your server, then you need to ask your host to enable SSL in PHP for you.
Also: Gmail may work okay for sending 50-100 emails per day. It depends though. See their Program Policies for Gmail which does not go into a lot of detail. It sounds like if you have a pre-existing relationship with the 50-100 people you are emailing per day, then you may not be violating any terms, but you may want to confirm that by contacting them directly or doing more searching about their terms.
Related Topics
PHP Multiple Ternary Operator Not Working as Expected
How to Use in Clauses with MySQLi Prepared Statements
MySQL PHP Select Count of Distinct Values from Comma Separated Data (Tags)
Is HTMLspecialchars Enough to Prevent an SQL Injection on a Variable Enclosed in Single Quotes
How to Add Paths to the Apache Path Variable
Utf-8 Encoding for Subject in Contact Form Email
Getting Cdata Content While Parsing Xml File
Call PHP from Virtual/Custom "Web Server"
Setting Document Root for Laravel Project on Apache Virtual Host
Inserting Line Breaks into PDF
Function Ereg_Replace() Is Deprecated - How to Clear This Bug
PHP Best Practices for User Authentication and Password Security
Get Characters After Last/In Url