I can't get cakephp3 to send emails. In cakephp2 I could do this no problem. I am using the latest WAMP, and cakephp3.3 on Windows 7. I tried to follow the directions but it looks like I am getting something basic wrong. Do I also need to configure Wamp as I checked the php.ini-development file but there is no smtp entry to change
error- stream_socket_client(): SSL operation failed with code 1.
OpenSSL Error messages: error:14090086:SSL
routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
stream_socket_client(): Failed to enable crypto
stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465
(Unknown error)
controller
public function singleTutorEmail(){
$email = new Email();
$email->transport('gmail3');
$to='jjxxx#gmail.com';
$subject='testing';
$message='hello, dfsfsdfsdf sdfsdf';
$email->from(['jjxxx#gmail.com' => 'test'])
->to($to)
->subject( $subject)
->send($message);
}
in app.php
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'localhost',
'port' => 465,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
'tls' => null,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
'gmail3' => [
'className' => 'Smtp',
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => 'jjxxx#gmail.com',
'password' => 'xxx',
'client' => null,
'context' => [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]
],
],
http://book.cakephp.org/3.0/en/core-libraries/email.html
Sending Mail using CakePHP 3.0
I had the same issue when making an HTTPS request using Cake\Network\Http\Client
To resolve the problem, I had to download "cacert.pem" file from https://curl.se/ca/cacert.pem
And then I updated php.ini by adding the following line:
openssl.cafile = <PATH_TO_CACERT_PEM>/cacert.pem
Don't forget to restart the web-server.
If the above thing doesn't make it work, try to update the OpenSSL library installed on your system.
I really hope this works for you too.
Related
I'm trying to send an email in cakephp (no need to use ssl at the time), config seems fine but I keep getting the error above, below is my smtp config:
public $smtp = array(
'transport' => 'Smtp',
'from' => array('test#mambihost.com' => 'Mambihost'),
'host' => 'mail.mambihost.com ',
'port' => 26,
'timeout' => 100,
'username' => 'test#mambihost.com',
'password' => 'secret',
'client' => null,
'log' => false,
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
Why could this be happening? I'm running this in a wamp on my server which is inside a LAN. I can ping the host from the server with no problem but my app doesn't seem to reach it or something.
Could you help me please?
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',
],
],
],
];
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.
I'm trying to send a verification email using Gmail but i get this error:
stream_socket_client(): SSL operation failed with code 1. OpenSSL
Error messages: error:14090086:SSL
routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
stream_socket_client(): Failed to enable crypto
stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465
(Unknown error)
I have followed the Configuring Transports guide.
Email::configTransport('gmail', [
'host' => 'ssl://smtp.gmail.com',
//'host' => 'smtp.gmail.com',
'port' => 465,
'username' => 'user#gmail.com',
'password' => 'password',
'className' => 'Smtp',
'log'=>true,
//'tls' => true
]);
$correo = new Email();
$correo
->transport('gmail')
->template('registro_exito')
->emailFormat('html')
->to('email#gmail.com')
->from('another_email#gmail.com')
->viewVars([
'nombre_sitio_secundario'=>$nombre_sitio_secundario,
'usuario_id'=>$usuario_id,
'token'=>$token
])
->send();
And this is the complete error log:
2015-09-24 20:09:39 Error: [Cake\Network\Exception\SocketException] stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
stream_socket_client(): Failed to enable crypto
stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error)
Request URL: /faindit/usuarios/registro
Stack Trace:
#0 C:\xampp\htdocs\faindit\vendor\cakephp\cakephp\src\Network\Email\SmtpTransport.php(204): Cake\Network\Socket->connect()
#1 C:\xampp\htdocs\faindit\vendor\cakephp\cakephp\src\Network\Email\SmtpTransport.php(159): Cake\Network\Email\SmtpTransport->_connect()
#2 C:\xampp\htdocs\faindit\vendor\cakephp\cakephp\src\Network\Email\Email.php(1301): Cake\Network\Email\SmtpTransport->send(Object(Cake\Network\Email\Email))
#3 C:\xampp\htdocs\faindit\src\Controller\Component\CorreoComponent.php(65): Cake\Network\Email\Email->send()
#4 C:\xampp\htdocs\faindit\src\Controller\UsuariosController.php(14): App\Controller\Component\CorreoComponent->registroExito(1, 'something#gm...')
#5 [internal function]: App\Controller\UsuariosController->registro()
#6 C:\xampp\htdocs\faindit\vendor\cakephp\cakephp\src\Controller\Controller.php(411): call_user_func_array(Array, Array)
#7 C:\xampp\htdocs\faindit\vendor\cakephp\cakephp\src\Routing\Dispatcher.php(114): Cake\Controller\Controller->invokeAction()
#8 C:\xampp\htdocs\faindit\vendor\cakephp\cakephp\src\Routing\Dispatcher.php(87): Cake\Routing\Dispatcher->_invoke(Object(App\Controller\UsuariosController))
#9 C:\xampp\htdocs\faindit\webroot\index.php(37): Cake\Routing\Dispatcher->dispatch(Object(Cake\Network\Request), Object(Cake\Network\Response))
#10 {main}
Worth to mention that openssl es enabled on php and also i have enabled the "access for less secure apps" on Gmail configs.
Thanks for helping!.
Ok i found the "error". Actually the code fine, the issue is with OpenSSL in php 5.6 that verifies every encrypted connection by default BUT my local Lampp doesn't count with a ssl certificate and that couses the error.
The solution is to avoid the verification, so the configTransport code would be like this:
Email::configTransport('gmail', [
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'user#gmail.com',
'password' => 'password',
'className' => 'Smtp',
'log' => true,
'context' => [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]
]);
I took as reference a PHPMailer answer but it was a little challenging knowing how to apply it to Cakephp3.
Hope this information is going to be helpful for somebody else.
Send a verification email using gmail in CakePhp 3
Follow these steps to send verification code using gmail
1. open your your project/config/app.php
2. In your app.php, replace(hide) this code
'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,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
write this code in your app.php
'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,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
'gmail'=> [
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'abc#gmail.com', //your gmail address
'password' => 'abcd123', //your gmail password
'className' => 'Smtp',
'log' => true,
'context' => [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]
],
],
3. Now open your Controller file and add this code
use Cake\Mailer\Email;
use Cake\Network\Exception\SocketException;
4. Write this code on function of your controller which is in used
$msg="Your Password is generate";
$email = new Email('default');
$email
->transport('gmail')
->from(['abcx.com' => 'abcx.com'])
->to($to)
->subject($subject)
->emailFormat('html')
->viewVars(array('msg' => $msg))
->send($msg);
now you can send email from your controller by using this code
5. if this error generate(SMTP server did not accept the password.) then do this process
i.> If the tips above didn't help, visit https://www.google.com/accounts/DisplayUnlockCaptcha and follow the steps on the page.
ii.> Allow access to your Google account
As a security precaution, Google may require you to complete this additional step when signing into a new device or application.
To allow access, click the Continue button below.
iii.> Account access enabled
Please try signing in to your Google account again from your new device or application.
6. run your application
I just developed a laravel web application with mail system.
i got error like
Connection could not be established with host smtp.gmail.com [Connection timed out #110]
controller
Mail::send('timesheet/emailtemplate',array('data'=>$query),function($message)
{
$message->to('example#gmail.com')->cc('expalecc#gmail.com')->subject('Work Report on - ');
});
email template file : emailtemplate.blade.php
<h2>hai</h2>
mail.php (config)
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => null, 'name' => null),
'encryption' => 'ssl',
'username' => 'myemail#example.com',
'password' => 'mypassword',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
instead of using smtp use Mandrill Driver it is simpler and quicker than use smtp server. by default laravel comes with Mandrill Driver. mandrill required Guzzle 4 HTTP library.. for geting that into your project add
"guzzlehttp/guzzle": "~4.0"
to your composer.json file (in your project root directory)
inside app/config/mail.php
change this line
'driver' => 'mandrill',
go to https://mandrillapp.com/settings
and sign up and generate api key
create an app/config/services.php configuration file if one does not already exist for your project and add below configurations and generated api key
return array(
'mailgun' => array(
'domain' => '',
'secret' => '',
),
'mandrill' => array(
'secret' => 'enter your mandrill api key here',
),
'stripe' => array(
'model' => 'User',
'secret' => '',
),
);
check this out this will be help full
Youtube video for setting up Mandrill for laravel