Extension YiiMaill (Swiftmailer) can't send SMTP from gmail - php

I've a PHP application that's running with Yii Framework and it's using the YiiMail extension that's is based in Swiftmailer.
My application was working perfectly yesterday, but today the follow error was launched:
fsockopen(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
My Yii app config:
'mail' =>
array('class' => 'application.extensions.yii-mail.YiiMail',
'transportType' => 'smtp',
'transportOptions' => array(
'host' => 'smtp.gmail.com',
'username' => '**#gmail.com',
'password' => '***',
'port' => '465',
'encryption'=>'tls' ),
'viewPath' => 'application.views.mail',
'logging' =>false,
'dryRun' => false
)
ANSWER: A FAST SOLUTION
My app is running in Windows, so I did a fast configuration to solve this problem at moment.
I did a configuration with sendmail and it enable into my php.ini file.
Ps: The main problem is if you have many apps running in the same php. How don't this problem to me, it's is stand alone application, I just did.
Something like this:
sendmail.ini
[sendmail]
smtp_server=smtp.gmail.com
smtp_port = 587
#default_domain = gmail.com it's is not necessary
auth_username= your gmail#gmail.com
auth_password=your password
php.ini
[mail function]
sendmail_path = "path to sendmail installation"
SMTP = smtp.gmail.com
smtp_port = 587

If your current config was previously working, then suddenly stopped. Consider looking into the following:
Generating an APP password for a gmail account
Enabling Less SecureApps settings for your gmail account
I have encountered a similar problem before, enabling Less Secure Apps, then when I set 2 Step Verification for my google account, it stopped working.
Then generating an APP password, did the trick!

This is my working smtp settings in my Yii2 project:
common/config/main-local.php
return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=bd-sys',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => '******#gmail.com',
'password' => '******',
'port' => 587,
'encryption' => 'tls',
],
],
],
];

Related

Cannot send mail with yii2 swiftmailer

I get error when trying send mail with Yii::$app->mailer->compose() function. This error appears when trying to connect smtp server, so I provide error message and mailer YII2 configuration
Expected response code 250 but got code "535", with message "535-5.7.8
Username and Password not accepted.
Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials 59sm3639427wrc.23 -> gsmtp"
Here is params from config/common.php file:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'port' => '587',
'encryption' => 'tls',
'username' => 'myemailbox#yahoo.com',
'password' => 'myemailpass',
'host' => 'smtp.mail.yahoo.com',
],
],
I already enabled "Allow apps that use less secure sign in" function in Yahoo account settings. Trying "app password" option but got the same result.
Before using yahoo smtp I tried it the same way with google smtp. Error message still refers to the https://support.google.com page. Is it possible Apache cached login and pass to smtp server?
Of course I checked google support page and followed instructions included https://accounts.google.com/DisplayUnlockCaptcha page.
try changing port
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'port' => '465',
'encryption' => 'tls',
'username' => 'myemailbox#yahoo.com',
'password' => 'myemailpass',
'host' => 'smtp.mail.yahoo.com',
],
],
I resolved this case, but didn`t detect what exactly was the cause. Maybe there was some sort of cache of config error.
So I put this direct setting right before compose function:
\Yii::$app->mailer->setTransport([
'class' => 'Swift_SmtpTransport',
'port' => '587',
'encryption' => 'tls',
'username' => 'myemailbox#yahoo.com',
'password' => 'myemailpass',
'host' => 'smtp.mail.yahoo.com',
]);
And it started to work.

Yii2: PHP mail without Swiftmailer?

It seems 1and1 web hosting service only allows plain PHP mail to send mail. But now Swiftmailer has thrown Swift_MailTransport away, so I'm unable to get simple PHP mail sending functionality using that class:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_MailTransport', // NOT WORKING ANYMORE!!!
],
]
Is there any other class apart from yii\swiftmailer\Mailer I might use to accomplish this task?
The entire mail transport is deprecated. Use sendmail or smtp
https://www.yiiframework.com/wiki/656/how-to-send-emails-using-smtp
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'localhost', // e.g. smtp.mandrillapp.com or smtp.gmail.com
'username' => 'username',
'password' => 'password',
'port' => '587', // Port 25 is a very common port too
'encryption' => 'tls', // It is often used, check your provider or mail server specs
],
],

yii2 Failed to authenticate on SMTP server with username using 2 possible authenticators

I am using swift mailer in yii2, i am using correct smtp setting still not able to send email.
I got this error - Failed to authenticate on SMTP server with username "example#example.com" using 2 possible authenticators
my swift mailer settings are:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'myHostName',
'username' => 'myUsername',
'password' => 'myPassword',
'port' => '465',
'encryption' => 'ssl',
],
],
I searched a lot on internet but found no solution, some people suggested that it would work by making 'useFileTransport' => false, but it is still not working.

Cakephp3 sending mails - no result

I'm trying to send email via cakephp3.
This is my app email config:
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
'tls' => null,
],
],
And this is controller :
public function index() {
$this->autoRender = false;
$email = new Email('default');
if (
$email->from(['mymail#gmail.com' => 'My Site'])
->to('mymail#gmail.com')
->subject('About')
->send('My message')) {
print 'ok';
}
}
And now, if i run this function, result is printed 'ok' on monitor.
But no mail is on my testing email box, even span, nothing.
My question is, why cakephp tells me that sending was done, but no mail is present on my box ?
Thank You.
Your configuration is incorrect. cakePHP attempts to send the e-mail via smtp to your localhost.
Most likely you do not have an MTA (ie. exim, dovecot) installed locally and the request gets dropped. This should be visible as an error in you logs (if enabled).
An easy solution is to change the configuration to a working email service for testing, for example Gmail.
Example:
Email::configTransport('gmail', [
'host' => 'smtp.gmail.com',
'port' => 587,
'username' => 'my#gmail.com',
'password' => 'secret',
'className' => 'Smtp',
'tls' => true
]);
Note that the host and port point to Gmail. This example is indicative and was taken from the official documentation.
More information on configuring email transports in cakePHP 3.0 here: http://book.cakephp.org/3.0/en/core-libraries/email.html#configuring-transports

Cakephp 3 Unknown Email error

I wanted to ask about sending emails in cakephp3.
I am using cakephp3 docs, and configured everything as example shows.
But, when I try to send mail, this error appears:
Could not send email: unknown
//app.php
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'smtp.gmail.om',
'port' => 465,
'timeout' => 30,
'username' => 'mymail#gmail.com',
'password' => 'password',
'client' => null,
'tls' => null,
],
],
ContactController:
public function contact() {
if (isset($this->request->data) AND ($this->request->is('post'))) {
$email = new Email('default');
if ($email->from(['mymail#gmail.com' => 'My Site'])->to('othermail#gmail.com')->subject('Hello')->send('Message')) {
//pr( 'ok');
}
}
}
Is this a generic error message (, which may have many reasons, in my opinion)? it has no value in context of debug.
You want to use an SMTP server, but you've configured to use the Mail transport!
The className option should be set to Smtp. The host should probably also be different (ssl:// prefixed), or you should enable TLS, please be sure that you read through the questions/answers found with the search linked below.
See also
Cookbook > Email > Configuring Transports
https://stackoverflow.com/search?q=[cakephp]+gmail
The host name in default configuration is incorrect.
it should be
'host' => 'smtp.gmail.com',
instead of
'host' => 'smtp.gmail.om',
One thing that's always forgotten is the Email profiles
`'Email' => [
'default' => [
'transport' => 'gmail', //this allows the email class to use the gmail settings
'from' => 'youremail#gmail.com',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
],
],`
And by the way you can set up multiple profiles for the like testing, development etc
use Cake\Mailer\Email;
Email::configTransport('gmail', [
'host' => 'smtp.gmail.com',
'port' => 587,
'username' => 'my#gmail.com',
'password' => 'secret',
'className' => 'Smtp',
'tls' => true
]);
Yous this code : Replace My#gmail.com and Secret with you credentials offcourse and after that use you code it will work.

Categories