Laravel's Mail notification won't send, but Laravel's Mail::Raw will - laravel

I have configured my SMTP server correctly in Laravel's env file, and can successfully send an email using Mail::raw e.g.
Mail::raw("This is a test message", function ($message)
{
$message->from(env("MAIL_ORDER_ADDRESS"), 'Orders');
$message->to('user#example.com');
$message->subject('Test Message');
});
However, when I use a laravel 5.3 mail notification, no email is received (nor is an error generated). I have tested the same notification code locally using mail trap and the notifications work correctly.
I can't understand how if the mail server is working and can be used with Mail::raw, it doesn't automatically work with notifications when I have tested locally and confirm they are coded correctly.
Note: Using shared hosting on NameCheap.
Any ideas?

FIXED: It was because I had not configured "From" in config/mail.php and because the domains didn't match, it wasn't set.

The opposite situation is occurring for me. I have the MAIL_DRIVER=mail set within the .env file.
I have set MAIL_FROM_ADDRESS & MAIL_FROM_NAME within the .env file and viewed the app/config/mail.php
Mail::raw is sending out email correctly via the Postfix logs but any emails sent via the new Laravel 5.3 Notifications is not working. No errors or any information writing to the logs.
There appears to be some other issue occurring.

I had the same issue. During testing for Mail::raw, i had set MAIL_ENCRYPTION to empty.
When I set MAIL_ENCRYPTION=tls for notify email, it started working.

Related

having issues on sending email in laravel 5.8

I am having issues on sending email via notification. I tried accessing the mailbox using the credentials I put in .env, the credential is good I am able to access the inbox but if I run the command sending email is failed.
on my .env
MAIL_DRIVER=smtp
MAIL_HOST=myhost
MAIL_PORT=465
MAIL_USERNAME=this#isworkingemail.com
MAIL_PASSWORD=pWdisWorking
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=this#isworkingemail.com
MAIL_FROM_NAME='AFTSCredit'
my function via
public function via($notifiable)
{
return [TwilioChannel::class,'database','mail'];
// return [TwilioChannel::class,'database'];
}
any idea? plase help thank you in advance!
Your error says Authentication error. This is nothing to do with Laravel/PHP mailer.
Try one of these below:
Clear cache
Check if you have modified config file. Make sure your .env variables are being pointed in your config file
Check if your server allows outbound emails
Check if you have right credentials such as host name, username, password
If you need extra authentication to allow using smtp services like google. You will need to activate to allow to use less secure app.
Finally, but not the least
If your mail server password contains a # then you should quote the environment string since everything after # will be taken as comment (starting in Laravel 5.8)
put the port and host as follows
MAIL_PORT = 587
MAIL_HOST= smtp.gmail.com
and also in your gmail . Disable two authentication and enabled unsecured apps
and then it would be okkay

Laravel not sending emails on Platform.sh to SendGrid

Im hosting a Laravel spark website on platform.sh. I have configured the environment variables within the platform.sh GUI to be what is suggested in their guides but for some reason SendGrid isn't picking up the emails.
I am using my SendGrid Log in details for username and password - I have also tried by using my API Keys.
There are no errors or anything and both SendGrid and Platform.sh are being useless saying they can't do or see anything, so im pretty lost as to where I go next. I have tried many various configuration options but none seem to have worked.
Here is the snippet of code to send the mailable in Laravel:
Mail::to($input['email'])->send(new BetaSignUp($referral, $referralFacebookUrl, $referralTwitterUrl));
Has anyone successfully got Laravel running on platform.sh, and sending emails via SMTP (SendGrid)
Thanks
EDIT
With the help of PSH i have run a python script they sent me to do a test on the container - this test was successful and I can see the email in SendGrid. Here is the test Script:
import smtplib
sender = 'info#smbstreams.live'
receivers = ['to-email#email.com']
message = """From: Deck Stream Team<info#smbstreams.live>
Reply-To: Deck Stream Team<deckstream#smbstreams.live>
To: To Person <to-email#email.com>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
server = smtplib.SMTP_SSL('smtp.sendgrid.net', 465)
server.set_debuglevel(1)
server.login("****", "****")
server.sendmail(sender, receivers, message)
Have you follow this https://docs.platform.sh/development/email.html#enablingdisabling-email
Email support can be enabled/disabled per-environment. By default, it
is enabled on the master environment and disabled elsewhere. That can
be toggled in through the web UI or via the command line, like so:
platform environment:info enable_smtp true

Laravel mail on shared hosting

I've a form contact on my website and I want the form to be sent via email when submitted.
I've tried it in xampp and it's working fine.
On shared hosting, it does not work.
I'm using my own custom domain smtp.
Someone can explain me why it's not working ?
Your shared hosting probably blocks outgoing SMTP connections. Many hosting providers do that to prevent spam. You can try using a HTTP/WEB API instead of SMTP to send email.
Some email APIs like Flute Mail allow you to set up an HTTP API connection which can immediately forward the request through your "custom domain smtp" server. So you can keep using your custom domain email server, but get an API for it.
Otherwise you'll have to set up a Web API yourself with an open source tool like Postal.
In your laravel .env file if add following parameters mentioned below and create a e-mail on your shared hosting and add username, password and host of your hosting.
MAIL_DRIVER=smtp
MAIL_HOST=shared_host_name
MAIL_PORT=587
MAIL_USERNAME=mail#sharedhost.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
I suppose then it would work fine.

C-panel not sending Laravel mail

So I currently have setup my laravel project in C-panel, and have updated the .env file to have the appropriate email address. When I, for instance, use the make:auth reset password feature it responds with the appropriate "We have e-mailed your password reset link!", but there is no mail sent.
I am not sure how to test this to find the hole in the problem. When I used mailtrap I was able to send and receive emails no problem, but there is some issue with the webmail in c-panel not processing and sending out an email from Laravel 5.4
Help please
change your .env file. set MAIL_DRIVER=mail it will start working. make sure you set from in mail.php
`

Laravel - How Do You Check If Current E-Mail Configuration is Valid Without Sending an E-Mail?

I've written a custom provider that overwrites the e-mail configuration settings in mail.php with values populated from a database. I have a feature in my app that lets users tests the e-mail configuration entered into the system.
I can test whether current credentials are valid by calling Mail::send(). If the configuration isn't valid, the send() method will return a reason on why sending the e-mail failed.
Is there anyway for me to check configuration without actually sending an e-mail?
You can use Mail::fake(); that doesn't send the email.
In you /config/mail.php set email driver from smtp to log. I usually do it in .env
MAIL_DRIVER=log
Then send the mail as usual. You'll get a log with your email in it in /storage/logs/laravel.log This would be the easiest method. Further you can use services like mailtrap.io or mailthief

Resources