I am trying to send a mail from my Laravel project but I keeping getting this error
"Connection could not be established with host smtp.hostinger.com :stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:\nerror:1408F10B:SSL routines:ssl3_get_record:wrong version number"
Below is my mail.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Mailer
|--------------------------------------------------------------------------
|
| This option controls the default mailer that is used to send any email
| messages sent by your application. Alternative mailers may be setup
| and used as needed; however, this mailer will be used by default.
|
*/
'default' => env('MAIL_MAILER', 'smtp'),
/*
|--------------------------------------------------------------------------
| Mailer Configurations
|--------------------------------------------------------------------------
|
| Here you may configure all of the mailers used by your application plus
| their respective settings. Several examples have been configured for
| you and you are free to add your own as your application requires.
|
| Laravel supports a variety of mail "transport" drivers to be used while
| sending an e-mail. You will specify which one you are using for your
| mailers below. You are free to add additional mailers as required.
|
| Supported: "smtp", "sendmail", "mailgun", "ses",
| "postmark", "log", "array", "failover"
|
*/
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
],
'ses' => [
'transport' => 'ses',
],
'mailgun' => [
'transport' => 'mailgun',
],
'postmark' => [
'transport' => 'postmark',
],
'sendmail' => [
'transport' => 'sendmail',
'path' => '/usr/sbin/sendmail -bs',
],
'log' => [
'transport' => 'log',
'channel' => env('MAIL_LOG_CHANNEL'),
],
'array' => [
'transport' => 'array',
],
'failover' => [
'transport' => 'failover',
'mailers' => [
'smtp',
'log',
],
],
],
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
/*
|--------------------------------------------------------------------------
| Markdown Mail Settings
|--------------------------------------------------------------------------
|
| If you are using Markdown based email rendering, you may configure your
| theme and component paths here, allowing you to customize the design
| of the emails. Or, you may simply stick with the Laravel defaults!
|
*/
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
When I vardumped the host I got smtp.hostinger.com, whereas that's not what I have in my configuration. I have cleared my cache several times too. Below is my .env file
APP_NAME='CarryWork'
APP_ENV=local
APP_KEY=base64:RHJPc1ZJY05wRjQ5Q29RNFphZTdJME9ES1hneHM2WjY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=carrywork.test
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=carryjob
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=xxxxxxxxxxxxxx
MAIL_PASSWORD=xxxxxxxxxxxxxx
MAIL_ENCRYPTION=tls
MAIL_FROM_NAME="${APP_NAME}"
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
Related
i got an error when trying to send an email using laravel auth.
this is my .env file
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=465
MAIL_USERNAME=myEmail#gmail.com
MAIL_PASSWORD=myPassword
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=hello#example.com
MAIL_FROM_NAME=Example
and this is my mail.php file
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 465),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
],
'ses' => [
'transport' => 'ses',
],
'mailgun' => [
'transport' => 'mailgun',
],
'postmark' => [
'transport' => 'postmark',
],
'sendmail' => [
'transport' => 'sendmail',
'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'),
],
'log' => [
'transport' => 'log',
'channel' => env('MAIL_LOG_CHANNEL'),
],
'array' => [
'transport' => 'array',
],
'failover' => [
'transport' => 'failover',
'mailers' => [
'smtp',
'log',
],
],
],
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
/*
|--------------------------------------------------------------------------
| Markdown Mail Settings
|--------------------------------------------------------------------------
|
| If you are using Markdown based email rendering, you may configure your
| theme and component paths here, allowing you to customize the design
| of the emails. Or, you may simply stick with the Laravel defaults!
|
*/
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
I've tried changing the value of MAIL_MAILER, MAIL_HOST,MAIL_PORT, MAIL_ENCRYPTION, MAIL_FROM_ADDRESS, and MAIL_FROM_NAME in .env file according to the information in the mail.php file. but it's still didn't work.Can someone please help me to resolve this, thank you.
.env file.
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=465
MAIL_USERNAME=myEmail#gmail.com \\ Gmail mail iD
MAIL_PASSWORD=myPassword \\ Gmail App generated password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=hello#example.com
MAIL_FROM_NAME=Example
Below link to generating an app password. https://support.google.com/mail/answer/185833?hl=en
OR
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=mygmail#gmail.com
MAIL_PASSWORD=******
MAIL_ENCRYPTION=tls
Localhost system MAIL_DRIVER=smtp was working fine, when you uploaded your project on cpanel then getting this error. So simple change in .env file
MAIL_DRIVER from smtp to sendmail.
More help also read: The connection could not be established with host smtp.gmail.com?
How to Send Email in Laravel with Example?
I have access to an X-CASH web script, but its email functions are not working. I have tried using SMTP, PHPMail, and Mailjet, but it's not sending emails. And also, I have tried going through the code, but I can't seem to pinpoint the error. I can attach whatever snippet of code or file you need to help me with the issue.
config/mail.php
return [
/*
|--------------------------------------------------------------------------
| Default Mailer
|--------------------------------------------------------------------------
|
| This option controls the default mailer that is used to send any email
| messages sent by your application. Alternative mailers may be setup
| and used as needed; however, this mailer will be used by default.
|
*/
'default' => env('MAIL_MAILER', 'smtp'),
/*
|--------------------------------------------------------------------------
| Mailer Configurations
|--------------------------------------------------------------------------
|
| Here you may configure all of the mailers used by your application plus
| their respective settings. Several examples have been configured for
| you and you are free to add your own as your application requires.
|
| Laravel supports a variety of mail "transport" drivers to be used while
| sending an e-mail. You will specify which one you are using for your
| mailers below. You are free to add additional mailers as required.
|
| Supported: "smtp", "sendmail", "mailgun", "ses",
| "postmark", "log", "array"
|
*/
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
],
'ses' => [
'transport' => 'ses',
],
'mailgun' => [
'transport' => 'mailgun',
],
'postmark' => [
'transport' => 'postmark',
],
'sendmail' => [
'transport' => 'sendmail',
'path' => '/usr/sbin/sendmail -bs',
],
'log' => [
'transport' => 'log',
'channel' => env('MAIL_LOG_CHANNEL'),
],
'array' => [
'transport' => 'array',
],
],
/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
/*
|--------------------------------------------------------------------------
| Markdown Mail Settings
|--------------------------------------------------------------------------
|
| If you are using Markdown based email rendering, you may configure your
| theme and component paths here, allowing you to customize the design
| of the emails. Or, you may simply stick with the Laravel defaults!
|
*/
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
I am trying to use laravel broadcast with pusher but my socket is showing null.
my env file
BROADCAST_DRIVER=pusher
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
PUSHER_APP_ID=12345
PUSHER_APP_KEY=ABCDEFG
PUSHER_APP_SECRET=HKLMNOP
PUSHER_APP_CLUSTER=mt1
PUSHER_APP_HOST=127.0.0.1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
in your broadcasting.php did you set 'options' => [ 'cluster' => '', 'encrypted' => true ], your broadcasting.php should look like below
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Broadcaster
|--------------------------------------------------------------------------
|
| This option controls the default broadcaster that will be used by the
| framework when an event needs to be broadcast. You may set this to
| any of the connections defined in the "connections" array below.
|
| Supported: "pusher", "redis", "log", "null"
|
*/
'default' => env('BROADCAST_DRIVER', 'null'),
/*
|--------------------------------------------------------------------------
| Broadcast Connections
|--------------------------------------------------------------------------
|
| Here you may define all of the broadcast connections that will be used
| to broadcast events to other systems or over websockets. Samples of
| each available type of connection are provided inside this array.
|
*/
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => 'ap2',
'encrypted' => true
],
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
'log' => [
'driver' => 'log',
],
'null' => [
'driver' => 'null',
],
],
];
I have this code on my controller.
// Queue job, Send notification
ExportCsvJob::dispatch(json_encode($exportdata))
->onConnection('database')
->onQueue('default');
.env file
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
config/queue.php
return [
'default' => env('QUEUE_DRIVER', 'sync'),
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
],
'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
'retry_after' => 90,
],
'sqs' => [
'driver' => 'sqs',
'key' => 'your-public-key',
'secret' => 'your-secret-key',
'prefix' => 'https://sqs.us-east-1.amazonaws.com/your-account-id',
'queue' => 'your-queue-name',
'region' => 'us-east-1',
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'default',
'retry_after' => 90,
],
],
'failed' => [
'database' => env('DB_CONNECTION', 'mysql'),
'table' => 'failed_jobs',
],
but when running php artisan queue:work --timeout=3600 never do anything,
I have this two records in jobs table
+-----+-----------------+------------------------------------------------------------------------------------------------------+----------+-------------+--------------+------------+
| id | queue | payload | attempts | reserved_at | available_at | created_at |
+-----+-----------------+------------------------------------------------------------------------------------------------------+----------+-------------+--------------+------------+
| 168 | shipment_export | {"displayName":"App\\Jobs\\ExportCsvJob","job":"Illuminate\\Queue\\CallQueuedHandler#call","maxTries | 0 | NULL | 1549262600 | 1549262600 |
| 169 | default | {"displayName":"App\\Jobs\\ExportCsvJob","job":"Illuminate\\Queue\\CallQueuedHandler#call","maxTries | 0 | NULL | 1549262834 | 1549262834 |
+-----+-----------------+------------------------------------------------------------------------------------------------------+----------+-------------+--------------+------------+
but when I changed QUEUE_DRIVER=sync to QUEUE_DRIVER=database It worked
Can give me explanation and possibly solution about my problem?
I know it is a duplicate issue in StackOverFlow (Laravel SwiftMailer : Expected response code 250 but got code "530", with message "530-5.5.1 Authentication Required) however, I'm done all the remedies discussed there but still no luck. I'm using mailtrap.io using my GMail account. Here is the .env file and mail.php (under config):
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=XXXX
MAIL_PASSWORD=XXXX
MAIL_ENCRYPTION=tls
mail.php
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailtrap.io'),
'port' => env('MAIL_PORT', 2525),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'niladriXXX#XXX.com'),
'name' => env('MAIL_FROM_NAME', 'Niladri Banerjee'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'sendmail' => '/usr/sbin/sendmail -t -i',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
After submitting the valid email from forgot password screen, it throws the following error:
Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required "
Please note: I have already ON 'Allow less secure apps' from "Sign-in & security" from my GMail.
Seeking your help.
PS: I'm running the project in localhost.
I' may suggest you use this as well, it worked for me,
Please Note if you're using Gmail: create a gmail app password, but be sure to your 2 Step verification set up, from sign in and securiity, the following link: https://myaccount.google.com/apppasswords to setup app password,
use that and follow procedure 2 after this return to set up gmail with smtp.
please note: code down below are for mail.php file
(do not forget to use: php artisan config:cache)
after changes to .env file as well
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailtrap.io'),
'port' => env('MAIL_PORT', 2525),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'lxxxx#xxxx.com'),
'name' => env('MAIL_FROM_NAME', 'myMail'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),//this setting in .env only leave as is here
'password' => env('MAIL_PASSWORD'),//this setting in .env only leave as is here
'sendmail' => '/usr/sbin/sendmail -bs',
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
//procedure 2 for gmail
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'lxxxx#gmail.com'),
'name' => env('MAIL_FROM_NAME', 'myMail'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),//this setting in .env only leave as is here
'password' => env('MAIL_PASSWORD'),//this setting in .env only (use app password you created for gmail and PLEASE leave as is here
'sendmail' => '/usr/sbin/sendmail -bs',
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
Hope it helps.
Kind regards
add MAIL_FROM=mailtrap.io username to your .env file
and php artisan config:cache.
if you see, mail.php needs this for authentication