2013-03-24 2 views

답변

1

운송 수단을 다른 운송 수단으로 교체하는 것만 큼 쉬운 일은 아닙니다. 앞에서 말했듯이 전송은 Illuminate \ Mail \ MailServiceProvider에서 하드 코딩됩니다.

당신은 아마 당신의 설정에 스와핑, 자신과/app.php 공급자 배열을 L4 메일 구현을 확장하고 싶습니다 : :

  • 은 메일 공급자에 대한 공급자의 배열을 교체

    설정/app.php

    ... 
    'providers' => array(
    'SendmailServiceProvider', 
    
    • 이진에 센드 메일 경로를 추가 :

    설정/mail.php

    'sendmail_path' => '/usr/bin/sendmail -bs', 
    
    • 당신의 composer.json 파일 자동로드 "응용 프로그램/라이브러리에서 classmap :"확인

    composer.json :

    ....  
    "autoload": { 
        "classmap": [ 
         "app/libraries", 
    .... 
    
    • y 우리 센드 메일 서비스 제공 업체 :

    응용 프로그램/라이브러리/

    <?php 
    
    use \Swift_Mailer; 
    use Illuminate\Support\ServiceProvider; 
    use Illuminate\Mail\Mailer as Mailer; 
    use Swift_SendmailTransport as SendmailTransport; 
    
    class SendmailServiceProvider extends ServiceProvider { 
    
        /** 
        * Indicates if loading of the provider is deferred. 
        * 
        * @var bool 
        */ 
        protected $defer = true; 
    
        /** 
        * Register the service provider. 
        * 
        * @return void 
        */ 
        public function register() 
        { 
         $this->registerSwiftMailer(); 
    
         $this->app['mailer'] = $this->app->share(function($app) 
         { 
          // Once we have create the mailer instance, we will set a container instance 
          // on the mailer. This allows us to resolve mailer classes via containers 
          // for maximum testability on said classes instead of passing Closures. 
          $mailer = new Mailer($app['view'], $app['swift.mailer']); 
    
          $mailer->setLogger($app['log']); 
    
          $mailer->setContainer($app); 
    
          $from = $app['config']['mail.from']; 
    
          // If a "from" address is set, we will set it on the mailer so that all mail 
          // messages sent by the applications will utilize the same "from" address 
          // on each one, which makes the developer's life a lot more convenient. 
          if (is_array($from) and isset($from['address'])) 
          { 
           $mailer->alwaysFrom($from['address'], $from['name']); 
          } 
    
          return $mailer; 
         }); 
        } 
    
        /** 
        * Register the Swift Mailer instance. 
        * 
        * @return void 
        */ 
        protected function registerSwiftMailer() 
        { 
         $config = $this->app['config']['mail']; 
    
         $this->registerSwiftTransport($config); 
    
         // Once we have the transporter registered, we will register the actual Swift 
         // mailer instance, passing in the transport instances, which allows us to 
         // override this transporter instances during app start-up if necessary. 
         $this->app['swift.mailer'] = $this->app->share(function($app) 
         { 
          return new Swift_Mailer($app['swift.transport']); 
         }); 
        } 
    
        /** 
        * Register the Swift Transport instance. 
        * 
        * @param array $config 
        * @return void 
        */ 
        protected function registerSwiftTransport($config) 
        { 
         $this->app['swift.transport'] = $this->app->share(function($app) use ($config) 
         { 
          extract($config); 
    
          // The Swift SMTP transport instance will allow us to use any SMTP backend 
          // for delivering mail such as Sendgrid, Amazon SMS, or a custom server 
          // a developer has available. We will just pass this configured host. 
          $transport = SendmailTransport::newInstance($sendmail_path); 
    
          // Once we have the transport we will check for the presence of a username 
          // and password. If we have it we will set the credentials on the Swift 
          // transporter instance so that we'll properly authenticate delivery. 
          if (isset($username)) 
          { 
           $transport->setUsername($username); 
    
           $transport->setPassword($password); 
          } 
    
          return $transport; 
         }); 
        } 
    
        /** 
        * Get the services provided by the provider. 
        * 
        * @return array 
        */ 
        public function provides() 
        { 
         return array('mailer', 'swift.mailer', 'swift.transport'); 
        } 
    
    } 
    

    SendmailServiceProvider.php

    정말 그것을 테스트하지만, 잘 작동합니다하지 않습니다. routes.php에 넣고 및 비트 재생하려고 :

    Route::get('/', function() 
    { 
        Mail::send('emails.auth.reminder', array('token' => '123456'), function($m) 
        { 
         $m->from('[email protected]', 'Laravel'); 
    
         $m->to('[email protected]')->cc('[email protected]'); 
    
        }); 
    }); 
    
+0

확실하지,하지만 귀하의 사용 사례에 대한 흥미 경우는 테일러의 핵심에 대체 교통로 PHP 메일 기능을 impemented 것 같다 : HTTPS : //github.com/laravel/laravel/blob/develop/app/config/mail.php –