0

I can't send email from my Laravel live project to an webmail account.

I have configured all possible files to send email.

config/mail.php

'driver' => env('MAIL_DRIVER', 'smtp'), 
'host' => env('MAIL_HOST', 'sg2plcpnl0003.prod.sin2.secureserver.net '),
'port' => env('MAIL_PORT', 465),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'info@ezmoverandrental.com'),
'name' => env('MAIL_FROM_NAME', 'Test'),
],
'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
'sendmail' => '/usr/sbin/sendmail -bs',

.env

MAIL_DRIVER=mail //also tried with 'sendmail' and 'mail'
MAIL_HOST=sg2plcpnl0003.prod.sin2.secureserver.net 
MAIL_PORT=587 //also tried with '645'
MAIL_USERNAME=info@ezmoverandrental.com
MAIL_PASSWORD='webmail_password'
MAIL_ENCRYPTION=ssl //also tried with 'tls'

Another interesting part is there is no error shows in my 'storage/log' file. Just I see in console that it returns '0'.

Here is the send mail method

public function sendMail($emailDataArray)
    {
        Mail::send('mail', $emailDataArray, function($message) use ($emailDataArray)
        {
            $message->to('info@ezmoverandrental.com')->subject('New Online Estimate');
            $message->from('info@ezmoverandrental.com');
        });

        return;
    }

That means my project is connected successfully with the webmail but unfortunately mail doesn't send.

I have already tried with 'sendmail' and 'mail' drive

Anybody Help Please.

Raff
  • 263
  • 1
  • 3
  • 15
  • `$message->to('webmail')` shouldn't here be a valid email address instead of 'webmail' string – lewis4u Feb 03 '19 at 20:12
  • I just give a sample name for the question. I have used the actual webmail here. For better understand I have update my ques – Raff Feb 03 '19 at 20:16
  • OK.... If you make the mail driver to log... then you will see if you get that mail BUT most important you will also see an error if there is any... inside `storage/logs/` – lewis4u Feb 03 '19 at 20:18
  • Yes I gt the mail in my log file after changing the mail driver to log. But there is no error !! Is that anything to do with my webmail settings ? – Raff Feb 03 '19 at 20:27
  • that means that something is not configured properly... sorry I can't help you further with that. Check the log again when you use the webmail driver – lewis4u Feb 03 '19 at 20:28
  • Thanks for your cooperation @lewis4u – Raff Feb 03 '19 at 20:31

2 Answers2

1

Your Method is Ok just Double check the values and make sure mail port,Drivers and the ENCRYPTION values are the same in the env and mail.php are same.

.env file

`MAIL_PORT=587 
MAIL_DRIVER=smtp
MAIL_ENCRYPTION=tls`

mail.php file

`'port' => env('MAIL_PORT', 587)
 'driver' => env('MAIL_DRIVER', 'smtp')
 'encryption' => env('MAIL_ENCRYPTION', 'tls') `
Waleed Raza
  • 73
  • 11
0

It seems your method is okay. Suggest you double check your mail host .env.

You could use Mail Gun or Mailtrap

**Mailtrap .env configuartion**
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your mailtrap username hashcode
MAIL_PASSWORD=your mailtrap password hashcode
Mcfaith
  • 269
  • 4
  • 16