Trying to Send Mail Using Swift Mailer, Gmail Smtp, PHP

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



Leave a reply



Submit