简体   繁体   English

Laravel邮件配置(如果使用提供程序)

[英]Laravel mail configuration if using providers

I want do a helper who send mails, i was start by doing provider and a custom class for my helper. 我想做一个发送邮件的助手,我首先要做的是提供程序和我的助手的自定义类。

  1. my provider register function: 我的提供者注册功能:

     public function register() { $this->app->bind('mailer.helper', function (Application $app){ return new MailerHelper($app->make('mailer')); }); } 
  2. my helper function: 我的助手功能:

     class MailerHelper implements SelfHandling{ /** @var Mailer $mailer */ protected $mailer; public function __construct(Mailer $mailer) { $this->mailer=$mailer; } public function sendFromContact(array $date){ $this->mailer->send('email_templates/contact', $date, function (Message $message){ $message->setTo('stroia.laurentiu92@gmail.com'); $message->setFrom('contact@dianabotezan.ro','Contact website Diana Botezan'); $message->setSubject('Forumlar contact'); }); } } 
  3. my configuration from config/mail.php: 我的配置来自config / mail.php:

    return [ 'driver' => env('MAIL_DRIVER', 'smtp'), 'host' => env('MAIL_HOST', 'smtp.gmail.com'), 'port' => env('MAIL_PORT', 587), 'from' => ['address' => null, 'name' => null], 'encryption' => env('MAIL_ENCRYPTION', 'ssl'), 'username' => env('my_gmal@gmail.com'), 'password' => env('mypassword'), 'sendmail' => '/usr/sbin/sendmail -bs', 'pretend' => false, ]'

and the problem is laravel have a bad configuration, here is my track from what he try to do: 问题是laravel配置错误,这是他尝试做的事情的跟踪:

Connection could not be established with host 127.0.0.1 [Connection refused #111]

1. in StreamBuffer.php line 265 2. at Swift_Transport_StreamBuffer->_establishSocketConnection() in StreamBuffer.php line 62 3. at Swift_Transport_StreamBuffer->initialize(array('protocol' => null, 'host' => '127.0.0.1', 'port' => '2525', 'timeout' => '30', 'blocking' => '1', 'tls' => false, 'type' => '1')) in AbstractSmtpTransport.php line 113

here you can observe he have other config then I set it. 在这里,您可以观察到他还有其他配置,然后我进行了设置。 What i do wrong ? 我做错了什么?

It looks like you've put your configuration in the wrong place. 看来您将配置放在错误的位置。

Instead of editing the config/mail.php file directly, you should put your mail configuration settings in the .env file at the root of your project. 而不是直接编辑config/mail.php文件,您应该将邮件配置设置放在项目根目录的.env文件中。

You can see here in the sample file shipped with laravel . 您可以在laravel随附的示例文件中看到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM