2014-11-23 64 views
0

我在邮件配置中将pretend更改为true。请检查http://laravel.com/docs/4.2/mail#mail-and-local-developmentLaravel假装没有显示cc邮件地址

现在日志显示为这样的地址。

[2014-11-22 17:12:49] production.INFO: Pretending to mail message to: [email protected], [email protected] [] [] 

但我也需要调试cc电子邮件。我该怎么做?

这是我的代码。

Mail::send($view, $data, function($message) use ($to, $cc, $subject) 
{ 
    foreach ($to as $toUser) { 
     $message->to($toUser['email'], $toUser['first_name'] . ' ' . $toUser['last_name']); 
    } 

    foreach ($cc as $ccUser) { 
     $message->cc($ccUser['email'], $ccUser['first_name'] . ' ' . $ccUser['last_name']); 
    } 

    $message->subject($subject); 
}); 

回答

0

请允许我在这里坦率。我是Laravel的新手,但我会尽我所能解释这一点。

虽然我知道如何调试电子邮件平台,但最简单的过程是通过C来完成。

我会尝试尽可能缓解。

首先,尝试使用laravel-debugbar(最新版本是4)。
这是一个能够过滤PHP调试栏的应用程序。
通过使用这个程序,你将能够连接和编辑输出功能(这里是链接了解更多信息:Debug bar

如果这是不行的,试图通过Ç调试

Fristly。 ,你会被插入调试选项编译ç程序,选项-G
之后,你就会启动GDB进入站台。
第三,你会打破点在C程序,具体说就是插入break line_number函数。
之后,您将在gdp调试器中打印变量值。

例如,你键入的命令,如打印Ĵ(GDP)P I(我会后的网站,我已经得到了从这些信息中,它会给你一个更多更广的演练)。

该过程有多种操作。
我强烈建议您造访:Debug C program using gdb。希望这有助于。

+0

感谢您的回复。但我只需要在邮件配置中使用假装值。 – 2014-11-23 12:25:26

+0

你的意思是你需要找到插入到加密中的值/函数,对吧? – 2014-11-23 13:38:13

+0

我用linke更新我的问题。请检查一下。 – 2014-11-25 11:20:45

0

为了本示例创建一个名为ExtendedMailer的新类,并将该文件保存在自动加载器能够找到的地方。根据您放置文件的位置,您可能需要在保存文件后运行composer dump-autoload

<?php 

use Illuminate\Mail\Mailer; 

class ExtendedMailer extends Mailer 
{ 
    protected function logMessage($message) 
    { 
     parent::logMessage($message); 

     $emails = implode(', ', array_keys((array) $message->getCc())); 

     $this->logger->info("Pretending to mail message to: {$emails}"); 
    } 
} 

创建一个新的服务提供者,在您的应用程序可以加载类的地方。如上所述,您可能需要运行composer dump-autoload

下面的代码只是扩展了原始的MailServiceProvider,但允许我们将不同的类绑定到IoC中,您会注意到new ExtendedMailer;我们之前创建的类。显然,如果你为班级命名,在这里反映这种变化。

<?php 

use Illuminate\Mail\MailServiceProvider; 

class ExtendedMailServiceProvider extends MailServiceProvider 
{ 
    /** 
    * Register the service provider. 
    * 
    * @return void 
    */ 
    public function register() 
    { 
     $me = $this; 

     $this->app->bindShared('mailer', function($app) use ($me) 
     { 
      $me->registerSwiftMailer(); 

      // 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 ExtendedMailer(
       $app['view'], $app['swift.mailer'], $app['events'] 
      ); 

      $this->setMailerDependencies($mailer, $app); 

      // 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. 
      $from = $app['config']['mail.from']; 

      if (is_array($from) && isset($from['address'])) 
      { 
       $mailer->alwaysFrom($from['address'], $from['name']); 
      } 

      // Here we will determine if the mailer should be in "pretend" mode for this 
      // environment, which will simply write out e-mail to the logs instead of 
      // sending it over the web, which is useful for local dev environments. 
      $pretend = $app['config']->get('mail.pretend', false); 

      $mailer->pretend($pretend); 

      return $mailer; 
     }); 
    } 
} 

在你的config/app.php,你会发现这样一行看起来像

'Illuminate\Mail\MailServiceProvider', 

你需要把它注释掉,并添加一行如下

'ExtendedMailServiceProvider', 

这是做什么的,取代Laravel知道你刚刚创建的邮件程序。你刚创建的那个和默认的一样,因为它只是扩展它,并且增加了logMessage函数的功能。

+0

我通过链接改进了问题。我只是想使用假装配置。不需要使用太多的代码来检查cc值。 – 2014-11-25 11:24:08

+1

我知道你想要使用假装值。您会注意到,将数据输出到日志的框架内的方法完全不会与Cc电子邮件进行交互。参见'/ vendor/laravel/framework/src/Illuminate/Mail/Mailer.php'并查找'logMessage()'方法。上述代码的必要性是因为它允许您扩展框架,并将CC电子邮件的日志记录添加到方法中 – 2014-11-25 11:43:57