2016-10-03 3 views
3

mailgun을 메일 드라이버로 사용 모든 수신자에게 모든 주소를 표시하므로 숨은 참조가 제대로 작동하지 않는 문제에 직면하고 있습니다. 문제를 해결할 수있는 해결책을 찾았지만 vendor/laravel/framework/src/Illuminate/Mail/Transport/MailgunTransport.php에서 MailgunTransport.php 파일을 편집해야합니다. 공급 업체 그래서 그 MailgunTransport 클래스를 확장하려고 폴더에 나는 메일 무시 MailGunTransport 클래스 Laravel 4.2

나는 두 개의 파일, CustomMailServiceProvider ...

<?php namespace custom\extensions; 

use Swift_Mailer; 
use Illuminate\Support\ServiceProvider; 
use Swift_SmtpTransport as SmtpTransport; 
use Swift_MailTransport as MailTransport; 
use Illuminate\Mail\Transport\LogTransport; 
use custom\extensions\CustomMailgunTransport; 
use Illuminate\Mail\Transport\MandrillTransport; 
use Swift_SendmailTransport as SendmailTransport; 

class CustomMailServiceProvider extends \Illuminate\Mail\MailServiceProvider { 

} 
있는 폴더라는 응용 프로그램/사용자 지정/확장을 만들었습니다 ... 파일을 변경하지 않으

... 그리고 CustomMailgunTransport.php는

<?php namespace custom\extensions; 

class CustomMailgunTransport extends Illuminate\Mail\Transport\MailgunTransport { 
    /** 
    * {@inheritdoc} 
    */ 
    public function send(Swift_Mime_Message $message, &$failedRecipients = null) 
    {   
     $client = $this->getHttpClient(); 
     $to = $this->getTo($message); 
     $message->setBcc([]); 

     $client->post($this->url, ['auth' => ['api', $this->key], 
      'body' => [ 
       'to' => $to, 
       'message' => new PostFile('message', (string) $message), 
      ], 
     ]); 
    } 
} 

CustomMailServiceProvider.php는 원래의 방법을 재정의하지만 CustomMailgunTransport \ 사용자 정의 \ 확장에 원래 MailgunTransport에서 전화를 변경하지 않습니다.

내가 composer.json의 classmap에서 새 파일의 응용 프로그램/사용자 지정/확장 디렉토리를로드 한

...

{ 
    ... 
    "autoload": { 
     "classmap": [ 
      ... 
      "app/custom/extensions"     
     ],  
    }, 
    ... 
} 

그리고 사용자 정의 '원래'를 분명히 \ 메일 \ MailServiceProvider '교체했다 \ extensions \ CustomMailServiceProvider '...

'providers' => array(
    ... 
    //'Illuminate\Mail\MailServiceProvider', 
    'custom\extensions\CustomMailServiceProvider', 
    ... 
), 

그러나이 시점에서 메일 기능을 호출하는 방법을 알지 못합니다. 메일 외관을 사용하려고하면 MailgunTransport.php의 원본 코드를 사용합니다.

사용자 정의 외관을 만들어야합니까? 만약 그렇다면 ... 어떻게 할 수 있습니까? 아니면 위의 코드에 문제가 있습니까? CustomMailServiceProvider를 만들지 않고 MailgunTransport.php 만 확장 할 수있는 방법이 있습니까?

답변

0

나는 CustomMailServiceProvider에 registerMailgunTransport 메소드를 포함하고 새로운 CustomMailgunTransport를 참조하여 해결했습니다.

CustomMailServiceProvider

<?php namespace custom\extensions; 

use Swift_Mailer; 
use Illuminate\Support\ServiceProvider; 
use Swift_SmtpTransport as SmtpTransport; 
use Swift_MailTransport as MailTransport; 
use Illuminate\Mail\Transport\LogTransport; 
use custom\extensions\CustomMailgunTransport; 
use Illuminate\Mail\Transport\MandrillTransport; 
use Swift_SendmailTransport as SendmailTransport; 

class CustomMailServiceProvider extends \Illuminate\Mail\MailServiceProvider { 
/** 
* Register the Mailgun Swift Transport instance. 
* 
* @param array $config 
* @return void 
*/ 
    protected function registerMailgunTransport($config) 
    { 
     $mailgun = $this->app['config']->get('services.mailgun', array()); 

     $this->app->bindShared('swift.transport', function() use ($mailgun) 
     { 
      return new CustomMailgunTransport($mailgun['secret'], $mailgun['domain']); 
     }); 
    } 
} 

CustomMailgunTransport

<?php namespace custom\extensions; 

use Swift_Transport; 
use GuzzleHttp\Client; 
use Swift_Mime_Message; 
use GuzzleHttp\Post\PostFile; 
use Swift_Events_EventListener; 

class CustomMailgunTransport extends \Illuminate\Mail\Transport\MailgunTransport { 
    /** 
    * {@inheritdoc} 
    */ 
    public function send(Swift_Mime_Message $message, &$failedRecipients = null) 
    {   
     $client = $this->getHttpClient(); 
     $to = $this->getTo($message); 
     $message->setBcc([]); 

     $client->post($this->url, ['auth' => ['api', $this->key], 
      'body' => [ 
       'to' => $to, 
       'message' => new PostFile('message', (string) $message), 
      ], 
     ]); 
    } 
}