【问题标题】:Laravel 4.2 Mail won't send. Stuck in pretendLaravel 4.2 邮件不会发送。卡在假装
【发布时间】:2016-06-09 15:01:23
【问题描述】:

我正在尝试发送邮件。我按照 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. [] []

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

编辑:

 <?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'),

 ));

【问题讨论】:

    标签: laravel-4


    【解决方案1】:

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

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

    【讨论】:

    • 我的app 目录中确实有一个local 目录。它只有一个带有调试设置的app.php 文件。我删除了它,但我仍然收到假消息?还有其他可能影响它的地方吗?
    • 你在你的app.php中设置环境了吗?这个的输出是什么? dd(App::environment());
    • @JagdeepSingh 我收到了local,一定是这样。但我没有看到可以在我的 app/config/app.php 中更改此设置的设置。也许我错误地删除了它?我在哪里可以编辑这个?
    • 抱歉环境设置不在 app.php 中,它位于 bootstrap/start.php 中
    • 你是否在 app/config/local/mail.php 中设置了假装为假?
    【解决方案2】:

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

    1) 删除供应商文件夹

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

    它帮助了我。

    【讨论】:

      猜你喜欢
      • 2017-07-16
      • 2018-05-12
      • 2016-03-18
      • 2015-12-19
      • 1970-01-01
      • 2015-09-07
      • 1970-01-01
      • 2015-01-21
      • 2014-05-10
      相关资源
      最近更新 更多