Send mails laravel5 with gmail in local - email

I have a problem sending emails
I have the following code in Laravel
The file mail.php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('smtp.gmail.com'),
'port' => env('MAIL_PORT', 465),
'from' => ['address' => 'email#gmail.com', 'name' => 'Kiko'],
'encryption' => 'ssl',
'username' => env('email#gmail.com'),
'password' => env(''),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
];
Log
[2015-05-29 13:27:48] local.DEBUG: Message-ID: <673a61b16f681371f9daa76f839527bd#localhost>
Date: Fri, 29 May 2015 13:27:48 +0000
Subject: Welcome to My Website
From: Kiko <email#gmail.com>
To: email#gmail.com
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
And the .env
MAIL_DRIVER=log
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME='email#gmail.com'
MAIL_PASSWORD=''
If in the file .env I change .log to smpt the log returns this message
Maximum execution time of 30 seconds exceeded
[2015-05-29 13:40:40] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Maximum execution time of 30 seconds exceeded' in C:\xampp3\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php:53
Stack trace:
#0 {main}
Anybody could help me to see error ?

you are using different ports in mail.php and .env

Related

How to set up a smtp connection on a domain email in laravel

I have a domain: www.mydomain.ro and i created an email like this: office#mydomain.ro
I'm trying to send emails from my laravel application(laravel 5.7) and i did this configurations:
In .env file:
MAIL_DRIVER=smtp
MAIL_HOST=office#my-domain.ro
MAIL_PORT=26
MAIL_USERNAME=office#my-domain.ro
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=null
And in config/mail.php:
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'mail.my-domain.ro '),
'port' => env('MAIL_PORT', 26),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'office#muy-domain.ro'),
'name' => env('MAIL_FROM_NAME', 'Office my-domain'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('office#my-domain.ro'),
'password' => env('mypassword'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
In Controller i'm doing this:
$data = array(
'name' => 'Ioan Andrei',
'body' => 'Test Email'
);
Mail::send('emails.demandreceived',$data,function ($message){
$message->from('office#my-domain.ro','TEST');
$message->to('ioan.andrei97#gmail.com');
$message->subject('Test email');
I get this error:
Connection could not be established with host office#msipremiumcars.ro [php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known #0]
What am i doing wrong?It's not working beacuse i'm trying to send them from my local server?
Can i use mailgun for example to send the email and still have the email send from office#mydomain.ro?
I tried to restart my local server after configs.
Laravel version: 5.7
The issue is the MAIL_HOST in the .env file. It needs to be hostname like my-domain.ro instead of an email address as you've currently entered office#my-domain.ro.

CakePHP - SMTP Error : 504 5.7.4 Unrecognized authentication type

I'am using cakePHP 2.0 version, While sending mail I get error as below.
SMTP Error: 504 5.7.4 Unrecognized authentication type
config/email.php
public $SendMail = array(
"SMTPAuth" =>true,
'SMTPSecure'=> 'tls',
'host' => 'outlook.office365.com',
'port' => 587,
'username' => 'xxx',
'password' => 'xxx',
'transport' => 'smtp'
);
If I user the same in PHPMailer its working fine.
In php version 5.6.30 its not working, Same configuration is working fine in version 5.5.38. What might be the issue?
I already referred few links given below. Which doesn't work for me.
1)
https://stackoverflow.com/questions/14809816/cakephp-send-mail-through-smtp-to-ms-outlook-smtp-error-504-5-7-4-unrecogni
2) https://stackoverflow.com/questions/23939427/change-cakeemail-smtp-authentication-type

PHP Mail (cakephp 3.4.x) error Peer certificate CN=\`cpanel44.proisp.no' did not match expected

I'm trying to send email from my cakephp app. The app url is subdomain.domain.com. We have set up domain.com to work with microsoft office 365.
Emails are being sent when I do it from my virtual box (cakebox), but when I try on the production server (hosted shared server by proisp.no), I can't. The hosted server is running linux with cPanel.
What is strange, is that just a few days ago, if not even until I made some changes today, I could send emails. The changes I did was adding a plugin, EmailQueue, and adding a new table for queue, and of course some simple coding. I will remind you, it works from my virtual box, but still not on the production server.
Also, neither sending mail with Cake\Mailer\Email works on prod. server now.
The error I get is:
SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS.
Email 1 was not sent
Warning Error: stream_socket_enable_crypto(): Peer certificate CN=`cpanel44.proisp.no' did not match expected CN=`smtp.office365.com' in [/home/username/tools/vendor/cakephp/cakephp/src/Network/Socket.php, line 433]
2017-05-09 22:41:42 Warning: Warning (2): stream_socket_enable_crypto(): Peer certificate CN=`cpanel44.proisp.no' did not match expected CN=`smtp.office365.com' in [/home/username/tools/vendor/cakephp/cakephp/src/Network/Socket.php, line 433]
Trace:
Cake\Error\BaseErrorHandler::handleError() - CORE/src/Error/BaseErrorHandler.php, line 153
stream_socket_enable_crypto - [internal], line ??
Cake\Network\Socket::enableCrypto() - CORE/src/Network/Socket.php, line 433
Cake\Mailer\Transport\SmtpTransport::_connect() - CORE/src/Mailer/Transport/SmtpTransport.php, line 226
Cake\Mailer\Transport\SmtpTransport::send() - CORE/src/Mailer/Transport/SmtpTransport.php, line 162
Cake\Mailer\Email::send() - CORE/src/Mailer/Email.php, line 2052
EmailQueue\Shell\SenderShell::main() - ROOT/vendor/lorenzo/cakephp-email-queue/src/Shell/SenderShell.php, line 100
Cake\Console\Shell::runCommand() - CORE/src/Console/Shell.php, line 472
Cake\Console\ShellDispatcher::_dispatch() - CORE/src/Console/ShellDispatcher.php, line 230
Cake\Console\ShellDispatcher::dispatch() - CORE/src/Console/ShellDispatcher.php, line 182
Cake\Console\ShellDispatcher::run() - CORE/src/Console/ShellDispatcher.php, line 128
[main] - ROOT/bin/cake.php, line 34
This is my setup:
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
// The following keys are used in SMTP transports
'host' => 'smtp.office365.com',
'port' => 587,
'timeout' => 30,
'username' => 'name#domain.com',
'password' => 'password',
'client' => null,
'tls' => true,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
'Debug' => [
'className' => 'Debug',
// The following keys are used in SMTP transports
'host' => 'smtp.office365.com',
'port' => 587,
'timeout' => 30,
'username' => 'name#domain.com',
'password' => 'password',
'client' => null,
'tls' => null,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
],
'Email' => [
'default' => [
'transport' => 'default',
'from' => 'name#domain.com',
],
'debug' => [
'transport' => 'Debug',
'from' => 'name#domain.com',
],
],

Could not open socket in zend

I have am using an SMTP mail server. When I register a new user, I recieve the following error message:
An error occurred
Could not open socket
Additional information:
Zend\Mail\Protocol\Exception\RuntimeException
File:
C:\wamp\www\zendtest\vendor\zendframework\zend-mail\src\Protocol\AbstractProtocol.php:209
Message:
Could not open socket
Code
<?php
return array(
'mail' => array(
'transport' => array(
'options' => array(
'host' => 'smtp.gmail.com',
'connection_class' => 'login',
'port' => '465',
'connection_config' => array(
'username' => 'varinderkumar.dx#gmail.com',
'password' => '********',
'ssl' => 'ssl'
) ,
) ,
) ,
) ,
);
?>
What should I do?
go to wamp->php->php.ini open this file and find ssl.dll after that remove ; symbol from starting of line. then save the file and restart the wamp. This is working for me.
For cPanel: Try disabling WHM >> Secuirty >> SMTP Restrictions.

CakePHP: send mail through SMTP to MS OUTLOOK -> SMTP Error: 504 5.7.4 Unrecognized authentication type

I figured that I'll try to find out if I can send mails via cmd line before writing a question here. So I followed these steps and sent an e-mail by cmd to myself and a collegue of mine who's working on the same app I am. The message from cmd line came in the format it should have come.
( internal app, should send mails only to my collegues' OUTLOOK accounts )
Everything seems to be connected fine so I figured I have an error in my cakePHP code:
Everything on mails code I have so far is this:
app/config/email.php
public $smtp = array(
'transport' => 'Smtp',
'from' => array('from#test.sk'),
'host' => 'ip_address_of_my_host',
'port' => 25,
'timeout' => 30,
'username' => 'from#test.com',
'password' => 'password',
'client' => null,
'log' => true,
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);
UsersController.php (test send mail function)
public function test_send_email() {
$this->autoRender = false;
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('smtp');
$email->from(array('from#test.com' => 'APP TEST'));
$email->to('me#test.com');
$email->subject('Subject of testing');
$email->send('Message of testing');
}
After 5 seconds of loading I get: SMTP Error: 504 5.7.4 Unrecognized authentication type
Solved:
I guess the authentication wasnt required on EXCHANGE, so I just removed the password parameter and works fine.
During research I found out this article, so the next step would be to contact EXCHANGE admins.
http://blogs.technet.com/b/exchange/archive/2006/12/28/3397620.aspx
I was getting the same error when using telnet on port 25. After changing to port 587, I was able to use authenticated SMTP.