I have this env variables:
MAIL_MAILER=smtp
MAIL_HOST=smtp.zoho.com
MAIL_PORT=587
MAIL_USERNAME=accounts#mozcoders.com
MAIL_PASSWORD=xxxxxxxxx
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=accounts#mozcoders.com
MAIL_FROM_NAME="${APP_NAME}"
INFO_MAIL_MAILER=smtp
INFO_MAIL_HOST=smtp.zoho.com
INFO_MAIL_PORT=587
INFO_MAIL_USERNAME=info#mozcoders.com
INFO_MAIL_PASSWORD=xxxxxxxxxx
INFO_MAIL_ENCRYPTION=tls
INFO_MAIL_FROM_ADDRESS=info#mozcoders.com
And this mail 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,
],
'info' => [
'transport' => 'smtp',
'host' => env('INFO_MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('INFO_MAIL_PORT', 587),
'encryption' => env('INFO_MAIL_ENCRYPTION', 'tls'),
'username' => env('INFO_MAIL_USERNAME'),
'password' => env('INFO_MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
],
When I send email using the default configurations it works fine, but when I use the custom configurations it returns an error:
local.ERROR: Expected response code 250 but got code "553", with message "553 Relaying disallowed as default#mail.com
" {"userId":1,"exception":"[object] (Swift_TransportException(code: 553): Expected response code 250 but got code \"553\", with message \"553 Relaying disallowed as default#mail.com
\"
Here is the code from my Notification file:
return (new MailMessage)
->mailer('info')
->subject('Some subject')
->markdown('mail.failure', ['data' => $this->failureData]);
I was able to achieve what i wanted by moving this array:
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
to desired mailers array:
...
'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,
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
],
'info' => [
'transport' => 'smtp',
'host' => env('INFO_MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('INFO_MAIL_PORT', 587),
'encryption' => env('INFO_MAIL_ENCRYPTION', 'tls'),
'username' => env('INFO_MAIL_USERNAME'),
'password' => env('INFO_MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
'from' => [
'address' => env('INFO_MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
],
Related
i have setup 2 smtp mailers:
'smtp' => [
'transport' => 'smtp',
'host' => smtp.gmail.org,
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => 'smtp1#gmail.com',
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'local_domain' => env('MAIL_EHLO_DOMAIN'),
],
'smtp-1' => [
'transport' => 'smtp',
'host' => smtp.gmail.org,
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => 'smtp2#gmail.com',
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'local_domain' => env('MAIL_EHLO_DOMAIN'),
],
and set failover:
'failover' => [
'transport' => 'failover',
'mailers' => [
'smtp'
'smtp-1'
],
],
the setup was was run fine.
$transport = $Mail::raw($message, function($msg) use ($to, $subject) {
$msg->to($to)->subject($subject);
});
the problem how can i get the actual sender mailer, since it can failed and swith to other mailer?
i try to get the return path with:
$header = $transport->getOriginalMessage();
$sender = $header->getReturnPath();
dd($sender);
but it return null;
i expect to get either smtp1#gmail.com or smtp2#gmail.com
I have a mailable, and I'd like it to always use a specific mailer. Currently, I send the mail like this:
Mail::mailer('smtp2')->to($recipient)->send(new AuthTokenMail());
What I'd like to do is set the mailer within the mailable, the same way I set the queue, like this:
class AuthTokenMail extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
public function __construct(int $code)
{
$this->onQueue('email2');
$this->mailer('smtp2'); // doesn't work!
}
...
for you to be able to use the specific mail details you need to set it up in your mail.php config file. like this:
'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,
],
'smtp2' => [
'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,
],
...
...
...
];
I got stuck on this error. I am trying to configure SMTP mail on laravel.
I have this issue when I want to send the password reset link:-
I found the reference but I have make change on 'host' and 'port'
'host' => env('MAIL_HOST', 'mailtrap.io'),
'port' => env('MAIL_PORT', 2525),
but I still have the same issue .
My config/mail.php:
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'mailtrap.io'),
'port' => env('MAIL_PORT', 2525),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello#example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
I'm trying to create a contact form using laravel 5.4 and I added my server email details to the .env and the mail.php but I'm getting this error
Swift_TransportException in AbstractSmtpTransport.php line 383:
Expected response code 250 but got code "421", with message "421 Unexpected failure, please try later
"
If I try this and I use mailtrap it works fine.
This is my mail.php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'info#website.co.za'),
'name' => env('MAIL_FROM_NAME', 'Info'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
My .env file
MAIL_DRIVER=smtp
MAIL_HOST=hosting.com
MAIL_PORT=587
MAIL_USERNAME=info#website.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=
Check the config/mail.php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', ''),
'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',
];
Make sure the .env file has the following
MAIL_DRIVER=smtp
MAIL_HOST=hosting website
MAIL_PORT=587
MAIL_USERNAME=your username
MAIL_PASSWORD=your password
MAIL_ENCRYPTION=tls
Also clear the config cache
php artisan config:cache
This is the way which I send the email:
Mail::send('emails.welcome', $data, function($message)
{
$message->from('us#example.com', 'Laravel');
$message->to('foo#example.com')->cc('bar#example.com');
$message->attach($pathToFile);
});
This is my mail configurations:
return [
'driver' => env('MAIL_DRIVER', 'mailgun'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
// 'from' => ['address' => '', 'name' => ''], //
'encryption' => 'tls',
'username' => env('****'),
'password' => env('****'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
];
This is my services configurations:
'mailgun' => [
'domain' => '****',
'secret' => '****',
],
When I get the email I see FROM is set to(None#mailgun.org). I would like to use different FROM based on different conditions, I don't want to hard code the FROM in the mail configurations. Please help.
The only potential problem I can spot, seems to be that you have commented out from in your mail configurations
'port' => env('MAIL_PORT', 587),
// 'from' => ['address' => '', 'name' => ''], //
'encryption' => 'tls',
This could be causing the problem with ->from not correctly overriding, as it might be dependent on it.