Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

brentxscholl's avatar

Mail won't send. Stuck in pretend

I'm trying to send mail. I followed the Laracast tutorial for sending mail with mandrill via https://laracasts.com/lessons/laravel-and-mandrill-in-minutes I also set up an event to trigger mail to send following this Laracast tutorial https://laracasts.com/series/build-a-laravel-app-from-scratch/episodes/27

Here is my app/config/app.php file

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

    /*

);

My app/config/mail.php file

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

);

my 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' => '',
    ),

);

Now when I hit the event that triggers the email to send, I check my laravel.log file and it says this

[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. [] []

It still says Pretending even though i have 'pretend' => false, in my app/config/mail.php file. The email never sends. I'm using real emails (i'm just not displaying them in this post) Am I missing something here? What else can be triggering mail to be in pretend mode?

0 likes
11 replies
erozas's avatar

Hey Brent, I've not used Mandrill with Events yet but I can tell you that I was having trouble sending emails that had no "Address" and "From" fields, even when I configured them on the mail.php file on the config directory. You could maybe try declaring them explicitly when sending the email to test if that's the issue:

I don't know if this is the issue but it's worth the try, I think that Mandrill is more strict regarding this kind of stuff (From and Address fields) that other transactional mail clients.

1 like
brentxscholl's avatar

@erozas Thanks for your reply. i currently have this as my code for sending the email

use Illuminate\Mail\Mailer as Mail;

abstract class Mailer {

    private $mail;

    /**
     * @param Mail $mail
     */
    function __construct(Mail $mail)
    {
        $this->mail = $mail;
    }

    /**
     * @param $user
     * @param $subject
     * @param $view
     * @param $data
     */
    public function sendTo($user, $subject, $view, $data)
    {
        $this->mail->send($view, $data, function($message) use($user, $subject)
        {
            $message->to($user->email)
                ->from('admin@acme.com')
                ->subject($subject);
        });
    }
} 

but It still sends in pretend mode.

dberry's avatar

do you have any mail.php config files in any other env location? like local/mail.php that it might be picking up?

brentxscholl's avatar

also when I dd(App::environment()); I get local not sure if that's a problem?

My bootstrap/start.php file looks like this

$env = $app->detectEnvironment(array(

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

));

dberry's avatar

no, that would only be a problem if you had

app/config/local/mail.php
brentxscholl's avatar

Ok well I'm still stuck in pretend. Does anyone have a possible solution?

foxted's avatar

Three questions:

  1. Are you using Laravel 4 or Laravel 5? @dberry answer is only valid for Laravel 4
  2. Why are you composing a new Mailer class?
  3. Why the class is abstract? Do you have a child class?

EDIT: Ok, didn't remember this screencast lol. I assume you are using Laravel 4. Have you tried setting 'encryption' => '' (no encryption) in app/config/mail.php?

brentxscholl's avatar

@foxted Thanks for the reply!

I'm using laravel 4.2

I just tried setting 'encryption' => '' in my app/config/mail.php but im still getting

[2015-04-08 03:33:33] local.INFO: Pretending to mail message to: xxxx@xxxxx.com [] []
[2015-04-08 03:33:33] local.INFO: Xxxxx.Registration.Events.UserRegistered was fired. [] []

Is there anything else at all that could be triggering the mail to be pretend? There must be some sort of check list I could do to make sure I'm not missing anything. This is driving me nuts that I cant find it :(

foxted's avatar

I have no other idea :/

Take a look at this repo and compare with your code to see if there are some differences.

It seems like you environment is misconfigured or not loaded properly.

brentxscholl's avatar

This problem is driving me nuts! If anyone is interested I'm willing to pay for someone to fix this problem for me

Please or to participate in this conversation.