How to send multiple domain email in laravel - php

I using laravel 7 and tried to send email using Mailtrap
and it's successfully
but actually i want to send gmail, yahoo and any other mail and multiuser
i using this setting in .env file
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=example#gmail.com //or any other emails not exactly gmail
MAIL_PASSWORD=somepassword
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=email#yahoo.com //or any other emails not exactly yahoo
MAIL_FROM_NAME="${APP_NAME}"

Here is an interesting article that describrs the solution to this problem
https://laravel-news.com/allowing-users-to-send-email-with-their-own-smtp-settings-in-laravel
Also here is a similar article from an older laravel version
multiple mail configurations

Related

Laravel - unable to send email on production

I'm using ovh cloud server and laravel forge to manage my server, I don't know what happened exactly, I have websites and even wordpress installed , everything was fine and can send email from all websites, nowadays no website send email also no error in the log files, and the email function works fine but no email in inbox or even spam
I've tried changing mail to sendmail, the same issue
please advice me
MAIL_DRIVER=mail
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=noreply#****com
MAIL_PASSWORD=*******
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=noreply#*****.com
MAIL_FROM_NAME=“****”
If your using gmail, delete and create new app password. Here is my config
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=***#gmail.com
MAIL_PASSWORD="*****"
MAIL_ENCRYPTION=tls

Send Email through Proxy Laravel

I am trying to send an email to a guest in laravel.
Below is my code:
Mail::to($requestor->email)->send(new ApprovedNotification(auth()->user()->name));
The question is how can I send the email through proxy? Does it requires any server side configuration or I can just set it in laravel? The code is running fine when I am using my home network but when using my company server, the SMTP can't be sent out. ( The weird thing is the Jetstream team invitation email can be sent, but the customized emails cant)
Below is my email configuration:
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=xxxxxx#gmail.com
MAIL_PASSWORD=xxxxxxx
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=xxxxxx#gmail.com
MAIL_FROM_NAME="${APP_NAME}"
Thanks in advance!
If you are using Gmail then you must generate App password.
https://support.google.com/accounts/answer/185833/sign-in-with-app-passwords?hl=en
then your mail configuration look like this
MAIL_MAILER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=587
MAIL_USERNAME=xxxxxxxxxx#gmail.com
MAIL_PASSWORD=xxxxxxxxxx
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=xxxxxxxxx#gmail.com
MAIL_FROM_NAME="${APP_NAME}"

SMTP in Laravel 7 godaddy hosting

So i have created an App in Laravel 7 and Deployed it in Godaddy Shared hosting, everything works except for the Mailing.
This is the .env values
MAIL_MAILER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=email#outlook.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=TLS
MAIL_FROM_ADDRESS=email#outlook.com
MAIL_FROM_NAME="YourName"
and the value in config/mail.php
'default' => env('MAIL_MAILER', 'smtp')
This is working Perfectly in Localhost, but when i deployed to goDaddy shared hosting, this doesnt seems to work.
I have tried changing the value to .env value to MAIL_MAILER=sendmail and congif/mail.php to 'default' => env('MAIL_MAILER', 'sendmail')
This doesnt show any error, also displayed to Success Message. but Mail not being sent.
What is the Fix ?
Change your .env
MAIL_MAILER=smtp
MAIL_HOST=localhost
MAIL_PORT=25
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=no-reply#your_godaddy_domain.com
MAIL_FROM_NAME="${APP_NAME}"
It seems that GoDaddy blocks SMTP ports to avoid the usage of third-party SMTP services [1] [2]. In order to send emails, GoDaddy says to use their SMTP relay server, which requires no authentication. So your env would look like:
MAIL_MAILER=smtp
MAIL_HOST=relay-hosting.secureserver.net
MAIL_PORT=25
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=email#yourgodaddydomain.com
MAIL_FROM_NAME="YourName"
Emails from shared hosts are highly likely to be blacklisted by most servers.
Your next option would be to use an email API such as Mailgun or Sendgrid (there are other providers too of cause). Both of them have a free plan which has a limited quota so you can try.
Finally, your last resort would be to ditch GoDaddy (I never liked them anyway) and move to another host provider. I suggest DigitalOcean (ask me for referral link to get $25 😄) or AWS.

Configuring a mail driver in Laravel (using MAMP)

I'm trying to use Laravel's auth package, and I'm getting various errors when trying to use its "send password reset link" option. I'm using MAMP as the server. My .env by default looks like this:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
I keep getting Swift_TransportException errors when I try to send mail.
Am I supposed to connect a Gmail address I own, using my email and password, essentially telling Laravel to use Gmail as the mail server? Isn't this a security risk since my password would be out in the open?
As an alternative, can/should I add a mail server to MAMP and use its credentials? Again, isn't that a security risk?
This configuration will save emails to log file:
MAIL_DRIVER=log
MAIL_HOST=mailtrap.io
MAIL_PORT=587
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=tls
If you register in Sendgrid, you will be able to use their smtp server.
This configuration will use Sendgrid as smtp Server:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=your_user_name_from_sendgrid
MAIL_PASSWORD=your_password_from_password
MAIL_ENCRYPTION=tls

Laravel email configuration for live server

I have installed laravel script on web server but unable to properly configure email settings. I want to use my hosting provider email on laravel script.
The script sends email when user register or request for verification code.
Find the .env file and edit the following with your smtp information:
MAIL_DRIVER=smtp
MAIL_HOST=host
MAIL_PORT=port
MAIL_USERNAME=username
MAIL_PASSWORD=password
MAIL_ENCRYPTION=null

Categories