I've got an error
Swift_TransportException in StreamBuffer.php line 265: Connection could not be established with host mailtrap.io [ #0]
May know what's the meaning of this? Glad that you could help me. thank you ^^
Mailing configuration can been seen at 2 places:
.env file
mail.php file located in config folder
You can update either of them, but it is strictly recommended to edit the .env file so as to avoid touching the default configurations.
Open .env file. You will see the mail configs in the bottom like so:
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
Now, login to your mailtrap.io account. From the Integrations dropdown, you need to select the Laravel option. When selected, the configs are provided below like this:
return array(
"driver" => "smtp",
"host" => "mailtrap.io",
"port" => 2525,
"from" => array(
"address" => "from#example.com",
"name" => "Example"
),
"username" => "your_username",
"password" => "your_password",
"sendmail" => "/usr/sbin/sendmail -bs",
"pretend" => false
);
Now open the mail.php file:
Go down to line number 57, it should have 'from' => ['address' => null, 'name' => null],. You need to replace this with what is provided in the mailtrap.io config.
So the updated from should be 'from' => ['address' => 'from#example.com', 'name' => 'Example'],.
Now, in your .env file, update the MAIL_USERNAME and MAIL_PASSWORD with the your_username and your_password respectively.
So, your mailing config in .env file should like:
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your_username
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=null
Done. You should now see the mails functioning without any further issues. Hope this helps you out.
Cheers.
You need to to set mailing provider details in .env file or you can add in config/mail.php
.env
MAIL_DRIVER=mail
MAIL_HOST=smtp.mandrillapp.com
MAIL_PORT=587
MAIL_USERNAME=test#gmail.com
MAIL_PASSWORD=test pass
MAIL_FROM=test#gmail.com
MAIL_NAME=test
MAIL_ENCRYPTION=null
Related
Hi there I want to send an email using laravel. In localhost every thing is fine what in heroku its
gives Failed to authenticate on SMTP server with username "mail#gmail.com" using 3 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "534"
I have added .env variables in settings as well
here is code
.env
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=mail#gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=mail#gmail.com
MAIL_FROM_NAME="${APP_NAME}"
controller
Mail::send('email', array(
'name' => $request->name,
'email' => $request->email,
'phone' => $request->phone_number,
'gender' => $request->gender,
'institute' => $request->institute
), function($message) use ($request){
$message->from($request->email);
$message->to('mail#gmail.com')->subject($request->get('Apply Form'));
});
Could you please try to use mail port 465 and encryption type as ssl in your SMTP settings?
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=mail#gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=mail#gmail.com
MAIL_FROM_NAME="${APP_NAME}"
I am using Laravel 8 + queues + Mailgun API to send emails from my local machine.
I can't send emails. I have this error :
[2020-12-19 11:50:26] local.ERROR: Connection could not be established with host smtp.mailgun.org :stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:1408F10B:SSL routines:ssl3_get_record:wrong version number {"exception":"[object] (Swift_TransportException(code: 0): Connection could not be established with host smtp.mailgun.org :stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:1408F10B:SSL routines:ssl3_get_record:wrong version number at C:\\Users\\Dominique\\Documents\\Workspace\\market-gardener\\market-gardener-back\\vendor\\swiftmailer\\swiftmailer\\lib\\classes\\Swift\\Transport\\StreamBuffer.php:269)
[stacktrace]
I think I have a configuration issues somewhere. I tried a lot of things without success. My conf :
.env :
MAIL_PORT=2525
MAILGUN_ENDPOINT=api.mailgun.net
MAILGUN_DOMAIN=sandbox___xxxxx_____________.mailgun.org
MAILGUN_SECRET=secret___xxxxxxxxxxxxxxxxx______
MAIL_ENCRYPTION=ssl
config/email :
'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',
],
Is this kind of conf correct? Where are my errors? Of course I already tried to clear the cache and config.
Here's a working version of the Mailgun setup I use:
MAIL_HOST=smtp.eu.mailgun.org
MAIL_PORT=587
MAIL_FROM_ADDRESS=address#example.com
MAIL_FROM_NAME=example
MAIL_USERNAME=address#example.com
MAIL_PASSWORD="123abc456def"
MAIL_ENCRYPTION=tls
The keys are coupled to the default config/mail.php file as seen here:
https://github.com/laravel/laravel/blob/8.x/config/mail.php
Note the usage of tls and port number 587. The MAIL_HOST may also differ. Mailgun should probably have a page on their website where this configuration is outlined.
A parameter was missing in the.env (see the doc here)
I only added MAIL_MAILER=mailgun in the .env , and it works fine now.
My .env is now :
MAIL_MAILER=mailgun
MAIL_PORT=2525
MAILGUN_ENDPOINT=api.mailgun.net
MAILGUN_DOMAIN=sandbox___xxxxx_____________.mailgun.org
MAILGUN_SECRET=secret___xxxxxxxxxxxxxxxxx______
MAIL_ENCRYPTION=ssl
You have to make sure you provide all the values of the environment variable
if not it won't work. in my own case, I added this line in my env file
MAILGUN_SECRET=6xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxd
Mail.php
return [
'driver' =>'smtp',
'host' => 'smtp.gmail.com',
//'port' => 587,
'port' =>465,
//'encryption' =>'tls',
'encryption' =>'ssl',
'username' => 'xxxxxxxx#gmail.com',
'password' => 'xxxxxxx',
// 'sendmail' => '/usr/sbin/sendmail -bs',
'sendmail' => '/usr/sbin/sendmail -t',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
Controller
$data = []; // Empty array
Mail::send('email.credentials', $data, function($message)
{
$message->to('xxxxxx#gmail.com', 'Jon Doe')->subject('Welcome!');
});
Error
Swift_TransportException Connection could not be established with host
smtp.gmail.com [A connection attempt failed because the connected
party did not properly respond after a period of time, or established
connection failed because connected host has failed to respond.
I Tried...
Change ssl / tls
Change the ports
Add "guzzlehttp/guzzle": "~5.3|~6.0" in composer.json
Add a new line in StreamBuffer.php
$options = array_merge($options, array('ssl' => array('verify_peer' =>
false,'verify_peer_name' => false,'allow_self_signed' => true )));
Please help .
Thank you.
1. Require illuminate/mail
Make sure you’re using the same version as your underlying framework (i.e. if you’re on Lumen v. 5.3, use composer require illuminate/mail "5.3.*").
composer require illuminate/mail "5.5.*"
2. Set up Lumen bootstrap/app.php
First, open your bootstrap.php and uncomment the following lines:
$app->withFacades();
$app->register(App\Providers\AppServiceProvider::class);
Also, add the following line below the last line you uncommented:
$app->configure('services');
This will allow you to define a ‘services’ config file and setup your mail service. Now I know that normally configuration is done in the .env file with Lumen, and we’ll use that shortly, but first we’ll need to write a small config file to map to the .env file.
3. Create your configuration files
Create a new folder at the root level of your install called config(if it doesn’t already exist). In the config folder, create two new files, one named services.php and another named **mail.php**.
In the services.php file paste the following:
<?php
return [
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
];
Lastly, add the following to your .env file:
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=<your-mailgun-domain>
MAILGUN_SECRET=<your-mailgun-api-key>
Make sure you replace those sneaky placeholders with your actual key and domain. If you’re not using Mailgun, you can always use the other mail providers Mail comes with; have a look at the docs if you plan on using a different provider, they are all easy to set up once you’re at this point.
4. Send Email!
To send an email, use one of the following in your classes (depending on your preference):
use Illuminate\Support\Facades\Mail;
$data = []; // Empty array
Mail::send('email.credentials', $data, function($message)
{
$message->to('xxxxxx#gmail.com', 'Jon Doe')->subject('Welcome!');
});
Finally, don’t forget to read the Laravel Mail docs for more info on how to use this great library.
Have you turned on 2 layers security in your Google account (email address you config in .env file) which uses to send email.
I am trying to use Mailgun
'driver' => env('MAIL_DRIVER', 'mailgun'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
MAILGUN_DOMAIN=xxxxxxxxxx,
MAILGUN_SECRET=xxxxxxxxxx,
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
The error is a strange one. Why would it be trying to connect to gmail?
Connection could not be established with host smtp.gmail.com [Connection timed out #110]
Edit:
Now I am getting
"mail" => array:9 [▼
"driver" => "smtp"
"host" => "smtp.mailgun.org"
"port" => "2525"
"from" => array:2 [▶]
"encryption" => null
"username" => null
"password" => null
"sendmail" => "/usr/sbin/sendmail -bs"
"markdown" => array:2 [▼
"theme" => "default"
My MAIL_HOST was mailtrap.io, and it seems that that URL is not valid any more.
When I changed it to smtp.mailtrap.io it started working again.
It's look like your .ENV still have cache.
Please try this way
php artisan config:cache
php artisan cache:clear
And try to debug at your Controller
dd(env('MAIL_HOST'));
If it's still get smtp.gmail.com. Please try this way.
Edit your config/app.php. And add below 'env' => env('APP_ENV', 'production'),
'mail_host' => env('MAIL_HOST', 'smtp.mailgun.org'),
And try to debug at your Controller
dd(config('app.mail_host'));
I'm sure it's will show smtp.mailgun.org
After that you can delete the line you has just added to config/app.php
In your .envfile you should set
MAIL_HOST=smtp.mailgun.org
MAIL_USERNAME=(yourmailgunusername)
MAIL_PASSWORD=(yourmailgunpassword)
MAIL_PORT=587
MAIL_DRIVER=mailgun
You can refer to these tutorials for more informations
Mailgun setup with Laravel 5 example
Ultimate Guide on Sending Email in Laravel
After
php artisan config:cache
php artisan cache:clear
You probably also need to restart your web server.
This should be something really simple but all the tutorials are too old and I really don't know what half of these things are:
In config/mail.ph
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => null, 'name' => null],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
So in my .env file I have:
MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=(Default SMTP Login <- found in mailgun)
MAIL_PASSWORD=(Default Password <- found in mailgun)
I beleive these are all good. Next in config/services.php I have
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
And further in my .env file:
MAILGUN_DOMAIN=(API Base URL <- found in mailgun)
MAILGUN_SECRET=(API Key <- found in mailgun)
but when I run the artisan queue:listen I get error:
Client error: `POST https://api.mailgun.net/v3/-API Base URL-/messages.mime` resulted in a `404 NOT FOUND` response.
where -API Base URL- is the value of the MAILGUN_DOMAIN variable in my .env file
I tried putting my domain name mail.mydomain.com in the MAILGUN_DOMAIN but then I got the message to activate my account although the account was already verified and hence, I believe, active.
I tried leaving the MAILGUN_DOMAIN empty and then I got the
`POST https://api.mailgun.net/v3//messages.mime` resulted in a `404 NOT FOUND`
So, my conclusion is there should be something between ...v3/ and /messages.mime but I can't figure out what.
EDIT:
I found this:
https://laracasts.com/discuss/channels/laravel/laravel-and-mailgun-1
and it seems i can remove the MAIL_USERNAME and MAIL_PASSWORD but I don't know where to find this sandboxxxxxxxx code.
The right thing to enter is your domain name that you set up in mailgun. In my case it was mail.mydomain.com.
However, I never bothered to activate the account (you need to give them your phone number so that's most likely the reason I skipped it) so I was getting this message. Problem is solved now.