Laravel 4.2 Mail不会发送。陷入假装

时间:2015-04-06 19:01:17

标签: laravel-4

我试图发送邮件。我按照Laracast教程通过https://laracasts.com/lessons/laravel-and-mandrill-in-minutes发送带有mandrill的邮件。我还设置了一个事件来触发邮件发送到此Laracast教程之后https://laracasts.com/series/build-a-laravel-app-from-scratch/episodes/27

这是我的app/config/app.php文件

<?php

return array(

/*
|--------------------------------------------------------------------------
| Application Debug Mode
|--------------------------------------------------------------------------
|
| When your application is in debug mode, detailed error messages with
| stack traces will be shown on every error that occurs within your
| application. If disabled, a simple generic error page is shown.
|
*/

'debug' => false,

/*
|--------------------------------------------------------------------------
| Application URL
|--------------------------------------------------------------------------
|
| This URL is used by the console to properly generate URLs when using
| the Artisan command line tool. You should set this to the root of
| your application so that it is used when running Artisan tasks.
|
*/

'url' => 'http://localhost',

/*

);

我的app/config/mail.php文件

<?php

return array(

/*
|--------------------------------------------------------------------------
| Mail Driver
|--------------------------------------------------------------------------
|
| Laravel supports both SMTP and PHP's "mail" function as drivers for the
| sending of e-mail. You may specify which one you're using throughout
| your application here. By default, Laravel is setup for SMTP mail.
|
| Supported: "smtp", "mail", "sendmail", "mailgun", "mandrill", "log"
|
*/

'driver' => 'mandrill',

/*
|--------------------------------------------------------------------------
| SMTP Host Address
|--------------------------------------------------------------------------
|
| Here you may provide the host address of the SMTP server used by your
| applications. A default option is provided that is compatible with
| the Mailgun mail service which will provide reliable deliveries.
|
*/

'host' => 'smtp.mailgun.org',

/*
|--------------------------------------------------------------------------
| SMTP Host Port
|--------------------------------------------------------------------------
|
| This is the SMTP port used by your application to deliver e-mails to
| users of the application. Like the host we have set this value to
| stay compatible with the Mailgun e-mail application by default.
|
*/

'port' => 587,

/*
|--------------------------------------------------------------------------
| Global "From" Address
|--------------------------------------------------------------------------
|
| You may wish for all e-mails sent by your application to be sent from
| the same address. Here, you may specify a name and address that is
| used globally for all e-mails that are sent by your application.
|
*/

'from' => array('address' => 'admin@acme.com', 'name' => 'Acme'),

/*
|--------------------------------------------------------------------------
| E-Mail Encryption Protocol
|--------------------------------------------------------------------------
|
| Here you may specify the encryption protocol that should be used when
| the application send e-mail messages. A sensible default using the
| transport layer security protocol should provide great security.
|
*/

'encryption' => 'tls',

/*
|--------------------------------------------------------------------------
| SMTP Server Username
|--------------------------------------------------------------------------
|
| If your SMTP server requires a username for authentication, you should
| set it here. This will get used to authenticate with your server on
| connection. You may also set the "password" value below this one.
|
*/

'username' => null,

/*
|--------------------------------------------------------------------------
| SMTP Server Password
|--------------------------------------------------------------------------
|
| Here you may set the password required by your SMTP server to send out
| messages from your application. This will be given to the server on
| connection so that the application will be able to send messages.
|
*/

'password' => null,

/*
|--------------------------------------------------------------------------
| Sendmail System Path
|--------------------------------------------------------------------------
|
| When using the "sendmail" driver to send e-mails, we will need to know
| the path to where Sendmail lives on this server. A default path has
| been provided here, which will work well on most of your systems.
|
*/

'sendmail' => '/usr/sbin/sendmail -bs',

/*
|--------------------------------------------------------------------------
| Mail "Pretend"
|--------------------------------------------------------------------------
|
| When this option is enabled, e-mail will not actually be sent over the
| web and will instead be written to your application's logs files so
| you may inspect the message. This is great for local development.
|
*/

'pretend' => false,

);

我的app/config/services.php

<?php

return array(

/*
|--------------------------------------------------------------------------
| Third Party Services
|--------------------------------------------------------------------------
|
| This file is for storing the credentials for third party services such
| as Stripe, Mailgun, Mandrill, and others. This file provides a sane
| default location for this type of information, allowing packages
| to have a conventional place to find your various credentials.
|
*/

'mailgun' => array(
    'domain' => '',
    'secret' => '',
),

'mandrill' => array(
    'secret' => 'MY SECRET API KEY IS HERE',
),

'stripe' => array(
    'model'  => 'User',
    'secret' => '',
),

);

现在,当我点击触发要发送的电子邮件的事件时,我会检查我的laravel.log文件,并说明了这个

[2015-04-06 17:47:04] local.INFO: Pretending to mail message to: example@hotmail.com [] []
[2015-04-06 17:47:04] local.INFO: Acme.Registration.Events.UserRegistered was fired. [] []

即使我的'pretend' => false,文件中有app/config/mail.php,它仍然会说假装。电子邮件从未发送过。我正在使用真实的电子邮件(我只是没有在这篇文章中显示它们)我在这里遗漏了什么吗?还有什么可以触发邮件进入假装模式?

编辑:

 <?php

 /*
 |--------------------------------------------------------------------------
 | Create The Application
 |--------------------------------------------------------------------------
 |
 | The first thing we will do is create a new Laravel application instance
 | which serves as the "glue" for all the components of Laravel, and is
 | the IoC container for the system binding all of the various parts.
 |
 */

 $app = new Illuminate\Foundation\Application;

 /*
 |--------------------------------------------------------------------------
 | Detect The Application Environment
 |--------------------------------------------------------------------------
 |
 | Laravel takes a dead simple approach to your application environments
 | so you can just specify a machine name for the host that matches a
 | given environment, then we will automatically detect it for you.
 |
 */

 $env = $app->detectEnvironment(array(

     'local' => array('homestead'),

 ));

2 个答案:

答案 0 :(得分:1)

您可能有一个覆盖邮件设置的localdev配置环境设置。

转到app/config/local/mail.phpapp/config/dev/mail.php并更改pretend设置(如果您不想单独配置,则删除文件)

答案 1 :(得分:0)

如果您的设置没有问题,那么:

1)删除供应商文件夹

2)运行 composer install 下载所有依赖项

它帮助了我。