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}"
Related
In Laravel 8 I was able to send an email verification email. And now in Laravel 9 email sent message appears but I don't receive an email.
I have used my correct mail host provided by domain with port, username, and password as previously and checked enough times. I have also changed ssl to tls but no success.
.env file
MAIL_MAILER=smtp
MAIL_HOST=mail.getalow.com
MAIL_PORT=465
MAIL_USERNAME=********
MAIL_PASSWORD=*********
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS="support#getalow.com"
MAIL_FROM_NAME="${APP_NAME}"
I also added 'verify_peer' => false in mail.php config file but no success.
mail.php
'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,
'verify_peer' => false, // <------ IT HAS TO BE HERE
],
my User.php model also has implements MustVerifyEmail as I do everytime.
class User extends Authenticatable implements MustVerifyEmail
In registration controller event(new Registered($user)); is presented
RegistrationController.php
// Register a new user
public function register(RegistrationRequest $request) {
$user = User::create($request->validated())->assignRole(['User', 'Commenter']);;
event(new Registered($user));
Auth::login($user);
return to_route('home')
->with(Helpers::Toast(
'Welcome ' . $user->name,
'Your account has been created.',
'success',
'5000'
));
}
I tried it from localhost to mailtrap it works. But when I upload it to server with all details of server in env file as above. I receive success message as in registration controller, but I don't receive activation email on my registered email.
I am using shared hosting, cpanel as hosting provider
What am I missing please help. I stucked on it for 4 days.
You said you are using cPanel shared hosting server.
There is no problem in your Laravel 9 code. The problem is on your DNS setting of your email in cPanel. You have to change CNAME, MX, TXT records on cPanel as provided by your hosting provider.
For example:
If you are using ohodomain hosting provider.
Go to account settings.
Select your domain from list of your domains.
Go to Manage Email.
There you will see the error with its solution that you have to solve.
Add the provided CNAME, MX, TXT records on your cPanel's Zone Editor.
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
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.
For my website I try to send emails from an alias (created alias from google for business). My mail function:
Mail::send('emails.tracktrace', ['text'=>$mailtext,'tracking' => $code,'email' => $email, 'name' => $name],
function ($m) use ($code, $email, $name) {
$m->from('info#mydomain.eu', 'Mydomain');
$m->to($email, $name)->subject('Track your package!');
});
Also in my config/mail.php I have:
'from' => ['address' => 'noreply#mydomain.eu', 'name' => 'mydomain'],
But both are ignored and the MAIL_USERNAME value set in my .env file (with the mail configuration) is used.
I ran into the same problem.. Turned out I tried to use a Gmail account which doesn't let you change the 'from' headers.
(see problem with php mail 'From' header)
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