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

tylernathanreed's avatar

Email works on Local Environment, but not Production Environment

Here are my environment variables related to email:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=********
MAIL_PASSWORD=********
MAIL_ENCRYPTION=tls

Both my Local and Production environment share these settings (Same Username and Password too).

And here's my AppMailer class that ends the emails:

<?php

namespace App\Mailers;

use Illuminate\Contracts\Mail\Mailer;
use App\Models\User;

class AppMailer
{
    protected $mailer;
    protected $from;
    protected $to;
    protected $view;
    protected $data = [];

    public function __construct(Mailer $mailer)
    {
        $this->mailer = $mailer;
    }

    /**
     * Delivers the View as an Email to the specified Receiver, given
     * a Sender and their Name.
     *
     * @param View      $view   The View for the Email.
     * @param array     $data   The Data for the View.
     * @param string    $to     The Email Address to send the Email to.
     * @param string    $from   The Email Address that sent the Email.
     * @param string    $name   The Name of the Person that sent the Email.
     *
     * @return void
     */
    public function deliver($view, $data, $to, $from = null, $name = 'No-Reply')
    {
        // Resolve From Address
        if($from == null)
            $from = env('MAIL_USERNAME');

        $this->mailer->send($view, $data, function($message) use ($from, $to, $name)
        {
            $message->from($from, $name)
                    ->to($to);
        });
    }

    /**
     * Sends an Account Validation Link to the specified User.
     *
     * @param User $user The specified User.
     *
     * @return void;
     */
    public function sendValidationRequest(User $user)
    {
        $this->deliver('emails.validate', compact('user'), $user->email);
    }

    /**
     * Sends a Password Reset to the specified User.
     *
     * @param User $user The specified User.
     *
     * @return void;
     */
    public function sendPasswordResetRequest(User $user)
    {
        $this->deliver('emails.password_reset', compact('user'), $user->email);
    }
}

When I register a User on my site, I expect said User to receive an email from me, prompting them to validate their account.

When I register locally, it works just fine. I receive the email in the inbox of the registered user's email account, and it's from the email listed in the Environment variables.

However, when I register on the production site (Which is hosted on GoDaddy), I receive the following error:

Swift_TransportException in AuthHandler.php line 181:
Failed to authenticate on SMTP server with username "cdp.admin-noreply@bible.org" using 2 possible authenticators

This is a followup from this thread, where I initially couldn't get emails to work on either environment.

Some things to note about the account being used as the sender:

  • The Email resolves as a Gmail account
  • 2-Step Verification is not enabled
  • Allow Less Secure Apps is enabled
  • The Account is managed through Google Apps to allow a separate domain (Like me@mydomain.com, where I log into Google using me@mydomain)

As far as I can tell, GoDaddy (the host provider for the Production Site) does not interfere with this. If the port or address didn't work because GoDaddy was blocking it, I would receive a different error (to my knowledge).

So now the question is: Why isn't this working on the Production site?

0 likes
30 replies
bashy's avatar

I would use a transactional email service for sending these types of emails. You can set them up with a domain like mail.domain.tld and then send them from the same email you have above. Gmail isn't meant for this and it will clog up your sent folder with these emails being sent.

tylernathanreed's avatar

I'll do that in the long run, but for now, this is fine. We're using a dedicated gmail account for automatic responses like this.

jrdavidson's avatar

@bashy Is there a video on Laracasts that talks about doing transactional emails not through your regular email provider?

jrdavidson's avatar

I never said you had to. All I asked was if there was a video I can watch.

bashy's avatar

@tylernathanreed There's no such thing because all gmail accounts are limited to a certain amount of emails being sent. If you're testing it and only sending a few, that's fine I guess (if it worked :D).

@xtremer360 Don't think there's a video with that direct wording but you should always use a proper system for it. There's a good number of free services for it anyway.

tylernathanreed's avatar

@bashy Gmail accounts are limited to sending 2,000 emails each day. Seeing as I don't expect to be getting more than 2,000 new users each day, I think I'm fine.

Also, I just tested this on both of my local environments. It works on both my Laptop and Desktop just fine, but the production server on GoDaddy fails to authenticate. I've quadruple checks for typos, and there aren't any.

I might give them a call later today, but I don't know why or how they would interfere with this.

andreasb's avatar

Basically you are saying that from your network the mailserver can authenticate but from godaddys it cant, right?

Maybe it is a network error, such as a blocked port? Or gmail refuses connections from this godaddy servers because someone else has been spamming?

Did you try to establish a connection manually via console from your godaddy server?

bashy's avatar

I'm sure it was much less than that when I looked!

This is why mailgun/mandrill API would be great because you don't need to use SMTP protocols or open ports for sending mail.

d3xt3r's avatar

@tylernathanreed Are you sure your production server support TLS or SSL or both? Have you tried switching the protocols?

tylernathanreed's avatar

@premsaurav Just tried that. Both of my local environments are happy to switch to SSL, but the production environment still doesn't like it.

@bashy If this keeps up, I might look into mailgun/mandrill.

tylernathanreed's avatar

Just got off the phone with GoDaddy, and they weren't much help. Once I explained the problem to them, they didn't really know about any possible solutions. This is really frustrating, as I need email to work for my application.

Any ideas, @bashy or @premsaurav ?

bashy's avatar

Probably missing some module or setting on the production server. We can't be much help I don't think. You will need to do some testing on the server to narrow it down.

tylernathanreed's avatar

@bashy what kind of tests? The code is the same in both environments.

I tried sending an email using Swift Mailer (Without all of Laravel's API), and that failed on the server too (same error). The local environments handled it just fine.

I'll try and look around on the server to see what might be causing issues. Is there anything specific I should be looking for?

aardalich's avatar

Even the free account at maligun has a generous allowance and does away with the smtp fun.

Rather quick and easy to get setup.

bashy's avatar

@tylernathanreed Like a test SMTP connection (HELO to gmail or something). It really is better to use an API to bypass these problems with ports/errors.

tylernathanreed's avatar

@aardalich, I'm trying to get mailgun set up, as their free plan should work for me. However, it hasn't been "quick and easy" like everyone has said. I'm having to change different DNS options on the server, which take a day or two to update, and there were some existing zone files on the server that were conflicting with mailgun's required configuration.

@bashy, How do I test a HELO connection? I saw some HELO stuff in the SwiftMailer library. I know that the script fails around the first HELO command, after following the logic in the library.

bashy's avatar

@tylernathanreed Would be like this

$ telnet smtp.gmail.com 25

Trying 74.125.71.108...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 smtp.gmail.com ESMTP v82sm13304213wmv.12 - gsmtp

HELO local.domain.name

250 smtp.gmail.com at your service
tylernathanreed's avatar

@bashy Apparently the telnet command is registered on GoDaddy servers. Any ways around this? Is this my problem?

tylernathanreed's avatar

@bashy So does this mean that I can't test the connection?

I still have no idea as to what needs to be done to fix this.

shez1983's avatar

not really an answer but mailgun.com allow 10k free emails per month.. not sure how many emails you send.. could that be a potential solution?

tylernathanreed's avatar

@shez1983 That's a temporary solution. I went ahead and did this, as I was able to get Mailgun set up on my GoDaddy server. However, I'm still unable to send emails through gmail, which is still a requirement.

Mailgun will work fine for a few months, but down the road I see it becoming an issue.

ben_s247's avatar

shouldn't be a requirement I very highly suggest removing it. Use mailgun and change the reply address. mailgun is extremely simple to setup in laravel but I see this google attachment a problem that isn't really going to be solved. You should just set up an email with your service I think I was paying $9 per month for the server and 5 or more email addresses that came with it. I'm not a fan of GoDaddy btw. just checked you should have like 500 email addresses to work with based on your domain so that should be enough. oh and even if you send 11,000 emails its still only going to cost 50c so wouldn't worry about it that much. plus it's far more professional to have a customised email domain than @gmail.com right!?

bashy's avatar

@ben_s247 They have Google Business Apps. You host your domain with their MX records and you get your own domain email.

ben_s247's avatar

yea but if you're paying for it already why not use it? Mailgun or something similar is built for high transactional emails. actually amazon ses is cheaper I'm just not sure about setting it up. laravel does support it so it's worth looking into if you really wan't to save some money as you get 62,000 messages per month on the free tier and even then it's $0.10/thousand. cool if Google Business Apps works find just set it up as the return address I. it's not particularly developer friendly is it?

bashy's avatar

@ben_s247 Paying for what? Google? You pay to get an inbox, that's where you'd be using it. I use Mandrill/Mailgun/Postmarkapp for transactional emails.

I'm not sure what you're trying to say :P use GBA or use Mailgun type service?

ben_s247's avatar

what no with godaddy comes with the hosting usually(most do usually) but I would only use it for incoming mail https://au.godaddy.com/hosting/web-hosting outgoing I would go with either Mandrill, Mailgun or Amazon SES and if you want it really cheap and reliable go Amazon SES https://aws.amazon.com/ses/ this would set the return email address as your hosted one or your GBA if you really want I would say avoid using google but you can always send the incoming mail where ever you want but outgoing go through one of the service made for it

just to be clear GBA incoming, Amazon SES(or the other two) outgoing.

tylernathanreed's avatar

@premsaurav As far as the "emails with delay", I'm getting no email at all.

Furthermore, I can't confirm that the ports are being blocked, as GoDaddy is successfully talking to Gmail. I'm getting an 'Authentication Failure' message, not a 'Cannot connect' error. I've tried both 465 and 587 for my ports, and I've already tried both SSL and TLS for my encryption. In all cases, I continue to get the same 'Authentication Failure' message that I initially described in the OP.

I'll try and bug GoDaddy again, and see if they are blocking ports, but I don't think that they are.

1 like

Please or to participate in this conversation.