Asked  8 Months ago    Answers:  5   Viewed   44 times

I am trying to send an email in laravel application. Here is my .env file:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=ehsan.sani91@gmail.com
MAIL_PASSWORD=**********
MAIL_ENCRYPTION=tls

And here is the Mail::send method:

Mail::send('email', ['name' => "EE"], function($m){
            $m->to('ee@dx.com', 'Malik')->subject('Subjet of the email');
        });

And here is the error:

Swift_TransportException in AbstractSmtpTransport.php line 383: Expected response code 250 but got code "530", with message "530 5.7.0 Must issue a STARTTLS command first. s16sm7748968wib.16 - gsmtp"

Any help?

 Answers

21

Well, I got it. Infact the email was not authenticated because that email required a mobile phone authentication after login. changing to other email address that required just login credentials, it worked.

.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=youremail@host.com
MAIL_PASSWORD=yourpassword
MAIL_ENCRYPTION=tls
Wednesday, March 31, 2021
 
Easen
answered 8 Months ago
84

You should try changing this :

MAIL_DRIVER=mail

There is no "mail" driver for laravel's mailing service (Laravel 5.5), you could have problems with the "smtp" because of wrong credentials. I think Laravel 5.2 might be using php's built-in "mail()" function when the "mail" driver is set, which could work on some shared hosting and fail on other.

Most shared hosting providers allow sending via the default server "sendmail" so you could also try this :

MAIL_DRIVER=sendmail

If you can't get "sendmail" or "smtp" to work, you could try the "mailgun" or any other external mail service provider. Mailgun for example gives you 10 000 free mails per month so you will not need any paid subscriptions and the set-up tutorials are very easy, plus you have great tools for monitoring the sent mails.

Saturday, May 29, 2021
 
ericstumper
answered 5 Months ago
28

Your error says:

SMTP ERROR: Failed to connect to server: Connection timed out (110)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

So let's look at https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting :

"SMTP Error: Could not connect to SMTP host."

This may also appear as SMTP connect() failed or Called Mail() without being connected in debug output. This is often reported as a PHPMailer problem, but it's almost always down to local DNS failure, firewall blocking (for example as GoDaddy does) or other issue on your local network. It means that PHPMailer is unable to contact the SMTP server you have specified in the Host property, but doesn't say exactly why. It can also be caused by not having the openssl extension loaded (See encryption notes below).

Some techniques to diagnose the source of this error are discussed below.

GoDaddy

Popular US hosting provider GoDaddy imposes very strict (to the point of becoming almost useless) constraints on sending email. They block outbound SMTP to ports 25, 465 and 587 to all servers except their own. This problem is the subject of many frustrating questions on Stack Overflow. If you find your script works on your local machine, but not when you upload it to GoDaddy, this will be what's happening to you. The solution is extremely poorly documented by GoDaddy: you must send through their servers, and also disable all security features, username and password (great, huh?!), giving you this config for PHPMailer:

$mail->isSMTP();
$mail->Host = 'relay-hosting.secureserver.net';
$mail->Port = 25;
$mail->SMTPAuth = false;
$mail->SMTPSecure = false;

GoDaddy also refuses to send with a From address belonging to any aol, gmail, yahoo, hotmail, live, aim, or msn domain (see their docs). This is because all those domains deploy SPF and DKIM anti-forgery measures, and faking your from address is forgery.

You may find it easier to switch to a more enlightened hosting provider.

Saturday, May 29, 2021
 
EastSw
answered 5 Months ago
59
  • I suspect the error is in this line

$m->from('no-reply@****.nl', 'No-Reply ****');

  • Please check if you can sent out an email via this email through Laravel

no-reply@****.nl

  • Check to see if you configure it properly in .env file
Saturday, May 29, 2021
 
CAMason
answered 5 Months ago
72

The Mail::send() method doesn't return anything.

You can use the Mail::failures() (introduced in 4.1 I think) method to get an array of failed recipients, in your code it would look something like this.

Mail::send('emails.users.reset', compact('user', 'code'), function($m) use ($user)
{
    $m->to($user->email)->subject('Activate Your Account');
});

if(count(Mail::failures()) > 0){
    $errors = 'Failed to send password reset email, please try again.';
}
Tuesday, August 3, 2021
 
Dzawor
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share