skip to Main Content

In facts I found this question: Laragon and Laravel – sendmail not working … but I decided to post a detailed new question, to get a response, that this issue is possibly a laravel bug… Thank you.

  • OS: Windows 10
  • Laravel Version: 8.75
  • PHP Version: 7.4.27
  • Database Driver & Version: sqlite

Description:

I trying around getting sendmail (Laragon) to work, but without luck.
File ‘.env’ got adjusted to use sendmail instead of smtp on a fresh laravel project.

Steps To Reproduce:

  • created new laravel project
    laravel new test
  • adjusted .env file:
MAIL_MAILER=sendmail
MAIL_SENDMAIL_PATH='C:LARAGONbinsendmailsendmail.exe -bs' 
  • run command:
    php artisan tinker
  • run tinker command:
    Mail::raw('Hello World!', function($msg) {$msg->to('[email protected]')->subject('Test Email'); });

After running the tinker command, the cmd is hanging…

Also tried different options on the sendmail flags:

  • sendmail.exe -t -i <<< tinker hangs
  • sendmail.exe -t <<< tinker hangs
  • sendmail.exe -bs <<< tinker hangs

I can see that the sendmail.exe is running (in task manager), but seems not be able to finish (waited several minutes).
Cancelation (CTRL-c) will close the tinker session and the sendmail.exe ist terminated.

With other php built-in mail function Laragon is working fine and also successfully catching the sent mails in the mail folder.

I always tried to clear configuration cache after every change of the .env file.
php artisan config:clear

Sending mail via php works fine as expected with the following code:

<html>
   
   <head>
      <title>Sending HTML email using PHP</title>
   </head>
   
   <body>
      
      <?php
         $to = "[email protected]";
         $subject = "This is subject";
         
         $message = "<b>This is HTML message.</b>";
         $message .= "<h1>This is headline.</h1>";
         
         $header = "From:[email protected] rn";
         $header .= "Cc:[email protected] rn";
         $header .= "MIME-Version: 1.0rn";
         $header .= "Content-type: text/htmlrn";
         
         $retval = mail ($to,$subject,$message,$header);
         
         if( $retval == true ) {
            echo "Message sent successfully...";
         }else {
            echo "Message could not be sent...";
         }
      ?>
      
   </body>
</html>

Any help really appreciated.

2

Answers


  1. Generally this happens when there is an authentication issue with sendmail.

    Make sure you have setup sendmail with your gmail credentials, as suggested by the Laragon Documentation

    Laragon Send Mail Settings

    Additionally, gmail disables "less secure apps" by default. Make sure your account has less secure apps enabled here too (or even better, use an Application Specific Password): https://myaccount.google.com/lesssecureapps

    Login or Signup to reply.
  2. output phpinfo() and check if you have the exact location define on sendmail_path

    you also need to define it inside config/mail.php like

    'sendmail' => [
        'transport' => 'sendmail',
        'path' => '/usr/sbin/sendmail -bs',
    ],
    

    or pull the value from your .env file MAIL_SENDMAIL_PATH

    'path' => env('MAIL_SENDMAIL_PATH')
    

    Additionally, you may try using smtp driver with localhost info in your .env file, you can see these details in phpinfo() as well

    MAIL_DRIVER=smtp
    MAIL_HOST=localhost
    MAIL_PORT=25
    MAIL_USERNAME=
    MAIL_PASSWORD=
    MAIL_ENCRYPTION=null
    

    try creating a route to send the email or dump the error

    Route::get('/test-mail', function () {
        try {
            $send = IlluminateSupportFacadesMail::mailer('sendmail')->send([], [], function ($message)  {
                $message
                    ->to('[email protected]')
                    ->from('[email protected]', 'Test')
                    ->subject( 'My Subject' )
                    ->setBody('Test Content', 'text/html');
            });
            dd($send);
        } catch (Exception $e )  {
            throw new Exception( $e->getMessage() );
        }
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search