我在邮件配置中更改了pretend
作为true
。 请检查 http://laravel.com/docs/4.2/mail#mail-and-local-development
现在日志显示这样的地址。
[2014-11-22 17:12:49] production.INFO: Pretending to mail message to: dinukathilanga@gmail.com, bbelekkaya@gmail.com [] []
但是我也需要调试抄送电子邮件。我该怎么做?
这是我的代码。
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);
});
请允许我在这里坦率地说。我是拉拉维尔的新手,但我会尽力解释这一点。
我确实知道如何调试电子邮件平台,最简单的过程是通过 C 来完成。
我将尽量简洁。
首先,尝试使用 laravel-debugbar(最新版本是 4)。
这是一个能够过滤PHP调试栏的应用程序。
通过使用此应用程序,您将能够附加和编辑输出函数(这是更多信息的链接:调试栏。
如果这不起作用,请尝试通过 C 进行调试。
首先,您将通过插入调试选项选项 -g 来编译 C 程序。
之后,您将在平台中启动 gdb。
第三,您将在 C 程序中中断点,具体来说,插入中断line_number函数。
之后,您将在 gdp 调试器中打印变量值。
例如,您将键入诸如print j和(gdp)p i之类的命令(我将发布我从中获取此信息的网站;它将为您提供更广泛的演练)。
此过程有多种操作。
我强烈建议您访问:使用 gdb 调试 C 程序。希望这有帮助。
为了这个例子,创建一个名为 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;
});
}
}
在您的配置/应用程序.php中,您会找到如下所示的行
'Illuminate'Mail'MailServiceProvider',
您需要将其注释掉并添加一行,如下所示
'ExtendedMailServiceProvider',
这样做是将Laravel知道的邮件程序替换为您刚刚创建的邮件程序。您刚刚创建的那个与默认的相同,因为它只是扩展了它,并向 logMessage 函数添加了功能。