How to configure Laravel mail.php to use built-in mail function?

后端 未结 4 1271
花落未央
花落未央 2020-12-13 07:25

I need to send an email via the mail() PHP function. I\'ve read somewhere that I have to change driver parameter in config/mail.php to

相关标签:
4条回答
  • 2020-12-13 07:52

    To do the same as mail() PHP function does, in most cases you should configure Laravel in the following way:

    Use sendmail, at .env:

    MAIL_DRIVER=sendmail
    

    Host, user, password, port and encryption are not needed.

    At this point, you may check if it already works, but sometimes the next step is also needed.

    Set a new .env option in config/mail.php:

    'sendmail' => env('MAIL_SENDMAIL', '/usr/sbin/sendmail -bs')
    

    Set the sendmail path in .env. You can check sendmail_path at phpinfo(), but it's usually this one:

    MAIL_SENDMAIL='/usr/sbin/sendmail -t -i'
    
    0 讨论(0)
  • 2020-12-13 08:02

    To use the email server running on localhost, your .env file should look like this (The PHP mail function doesn't need a username or a password)

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

    Then, update the configuration cache:

    php artisan config:cache
    
    0 讨论(0)
  • 2020-12-13 08:07

    You have to set your mail Configuration in .env file. Here you have to set all your mail driver and all details. Plase see this documentation https://laravel.com/docs/5.0/mail

    0 讨论(0)
  • 2020-12-13 08:16

    You can set your mail configuration .env file like

    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.gmail.com
    MAIL_PORT=587
    MAIL_USERNAME=youremail@gmail.com
    MAIL_PASSWORD="password"
    MAIL_ENCRYPTION=tls
    

    also set configuration in config/mail.php like:

    'from' => ['address' => 'youremail@gmail.com', 'name' => 'Test'],

    then you can clear the cache:

    php artisan cache:clear
    php artisan config:cache
    php artisan cache:clear
    
    0 讨论(0)
提交回复
热议问题