Magento not sending emails?

UPDATED (25/01/15)

A change in Magento 1.9.1.0 means that the new order emails are now not sent upon the processing of the order (as they used to be) but instead sent via a cron job. If you’ve followed the information in this post and all other emails, other than new order emails, are being sent properly, then the next thing to do is check that your cron job is set up and running properly.

ORIGINAL POST

Frequently I’ll get people getting in touch with me because their Magento installation isn’t sending emails (or has suddenly stopped sending emails). It can be for any number of reasons, but before doing anything else there are two quick tests to check – is mail() (the PHP function that Magento uses to send emails by default) enabled in the first place, and secondly, is it sending emails.

Both of these checks can be done outside Magento. For the former, it just requires a very simple script (download it below) which checks to see if mail() is enabled on the server – it’s frequently not enabled for security reasons, because if hijacked it can be used to send large quantities of spam email very quickly.

The following script very simply checks if mail() is enabled on the server, and tells you :

<?php
if(function_exists('mail')) {
	echo 'mail() is enabled';
} else {
	echo 'mail() is not enabled';
}  
?>

To run it, download the example file below, upload it to the web root of your site as mail.php, then visit http://www.yoursite.com/mail.php in a browser to see the output.

If mail() isn’t enabled, then you’ll have to liaise with your hosts to get it turned on, or alternatively set up Magento to use a separate mail server to send its emails through.

If mail() is enabled, but Magento’s not sending emails, then the next step is to send a test email from the server, not from Magento. Again, this can be done very simply using a script along the lines below.

<?php
$to = "you@youraddress.com";
$subject = "Test email";
$message = "This is a test email.";
$from = "from@fromaddress.com";
$headers = "From:" . $from;
if (mail($to, $subject, $message, $headers)) {
	echo("Your message has been sent successfully");
	} else {
	echo("Sorry, your message could not be sent");
}
?>

Simply download it, change the “to” and “from” addresses, and then upload it to your server as test-email.php (or similar) and visit http://www.yoursite.com/test-email.php in a browser. If it reports that the message has been sent successfully, then you should receive the test email at the “to” address relatively shortly thereafter. If it is, then it’s indicative that the error lies with your Magento installation or its configuration, and not with your server configuration.

If, however, it reports that the message has been sent successfully but it doesn’t make it to the “to” email address, then the first thing to check is that it’s not in the spam bin (which is a topic for a whole ‘nother post). If it’s not, then it’s almost certain that the error lies somewhere in your server configuration…so at least you now know where best to start looking!

77 comments

  • sandip

    Hello Team,
    i have worked on one magento website. i found 1 issue on this website. when we register with this particular email provider (.aol.com), i got register email. but when i place order with this email , i am not recieving any order confirmation email.
    please help me in this.

    • Giles Bennett (author)

      Check that your cron jobs are in place.

      Kind regards,

      Giles

  • Farhan

    Hi Giles,

    I have run both the scripts mentioned in the article. First on says “mail is enabled” and second one says “Sorry, your message could not be sent”. I’m using Magento 1.8 version and hostgator as my hosting account. None of my transactional emails are working (new account confirmation, reset password email, newsletter subscription etc) nothing is working. Please help sort out the issue, struggling with the same since last few days.

    – Farhan

    • Giles Bennett (author)

      Farhan,

      You’ve been in touch via email since posting the above, and I’ve replied there.

      Kind regards,

      Giles

  • Andrew Smith

    Hi
    We use gmail with our own domain for our emails and whenever we change the password in gmail, the emails stop being sent from our website. Emails such as order emails or customer service contact us form emails.

    I remember a while back learning how to change the password for the email address in Magento somewhere but now I cannot remember or find it.

    Please can you direct me how to do this? We changed our password at 7pm tonight on gmail, and since then have had around 20 orders but not a single order email has been sent.

    Many thanks in advance.

    • Giles Bennett (author)

      Andrew,

      Sounds like a bit of an odd one – the password change shouldn’t have any impact on your store sending emails out. Look into a solution like SMTP Pro, perhaps?

      Kind regards,

      Giles

    • Giles Bennett (author)

      Dimitri,

      This article is about Magento 1, not Magento 2, I’m afraid.

      Kind regards,

      Giles

  • Miguel

    Hello, we have a store in French and English.
    The French version sends automatic emails to customers after new purchase. But the english store does not send the automatic emails. Can you tell us why ? Thanks a lot. Miguel

    • Giles Bennett (author)

      Miguel,

      Is there store-specific configuration? The cron job would be global, so it’s unlikely to be that – more likely to be that the English store isn’t set to send order confirmation emails?

      Kind regards,

      Giles

  • Andhi Irawan

    Thank you for the scripts.
    Really helped me.

  • Adrian

    Hello, I found my test email in my spam bin. So what is the problem of this? How can I make the magento to be able to sent emails?

    • Adrian

      Hi Giles,
      From your script, I can send the Email from my server. I can see the email in spam bin. But from magento admin panel I cannot send any email to clients. I guess something wrong about the configuration of the email? I think i set it correctly of the email setting. I also set up the Cron job, although my magento ver. is 1.8.1.0. I’m lost here. Can I get some help here please. Thank you.

      • Giles (author)

        Adrian,

        Check your server logs, or ask your hosts to check your server logs, to see if any outgoing emails from Magento are being sent. If not, then they should be able to help you resolve the issue. One possibility would be to switch to sending the emails via SMTP using an extension such as this one which sends the emails in a different method.

        Kind regards,

        Giles

    • Giles (author)

      Adrian,

      If you found the test email in your spam bin then the server is sending emails, but Magento may not be.

      Kind regards,

      Giles

  • preet Kaur

    Hello Giles,

    My sales emails are not sending my magento website is implemented on magento 1.7.0.2.
    http://mccauleyolivegroves.com/

    I have checked all the things cron joib is working fine and also enable all the setting.

    please help me its very urgent.

  • Caba

    Hi Giles,

    I have this issue. The mails have been working fine and still do on all store views except one. In this particualr store view only the order confirmation (and maybe new account and other native magento emails) does not send.

    Any pointers for this scenario?

    • Giles (author)

      Caba,

      Check if they’re disabled in the configuration for that store view and not others. If the store is on a different domain name, check the mail settings for that specific domain.

      Kind regards,

      Giles

      • Caba

        Thanks for your time and advice. But I can’t figure it out.

        Would you be interested in doing this for me as a job?

          • Bao

            Giles/Caba, Have you tracked this down yet? I’ve been working on the exact same issue on this end. This is the first thread I’ve come across that had same symptoms – specifically the multistore scenario where other stores send, and one does not.

            Thanks for any insight you may have.

            Bao

          • Giles (author)

            Bao,

            At the time of writing, we haven’t heard from Caba.

            Kind regards,

            Giles

  • Lisbeth macias

    a mi me funcionaron los dos archivos, me aparece la funcion mail activada y si me envio los correos pero las notificaciones de magento no me llegan a mi correo.

    • Giles (author)

      Lisbeth,

      I’m afraid that we can only reply to comments made in English.

      Kind regards,

      Giles

  • Sourav

    Hi,
    I test your script, and I had.

    mail() is enabled
    Sorry, your message could not be sent

    What can I do with that?

    • Giles (author)

      Sourav,

      Check the server logs for any indication why the email couldn’t be sent.

      Kind regards,

      Giles

      • sourav

        Thanks for reply sir.
        i am new in magento.
        How to Check the server logs?

        • Giles (author)

          Sourav,

          Speak to your hosts.

          Kind regards,

          Giles

  • jaydel sparks

    My confirmation email is not working i don’t know why, but in my order view displayed Order # 10000000020 (the order confirmation email was sent) the client is notified.
    i think its not about the cron because the invoice and shipping email are working fine,

    any suggestions?

    • Giles (author)

      Jaydel,

      Invoice and shipping emails aren’t necessarily sent on a cron job, so do double check that cron is set up properly. Then check the outgoing server logs to see if the email was sent and didn’t bounce back. Then check the spam bin on the recipient email address.

      Kind regards,

      Giles

  • Manoj

    I have checked the first mail file. It shows
    Email is enable.

    But Still I am not getting email once I placed order. What should I do????

    • Giles (author)

      Manoj,

      Have you checked that cron jobs are set up?

      Kind regards,

      Giles

      • Manoj

        app/code/core/Mage/Core/Model/Email/Template.php
        Change Line 407
        if ($this->hasQueue() && $this->getQueue() instanceof Mage_Core_Model_Email_Queue) {
        to
        if (!($this->hasQueue() && $this->getQueue() instanceof Mage_Core_Model_Email_Queue)) {

        I have made changes in this.Now I am able to send order email but not other email. Like invoice and ship.
        and How can I check corn job???

      • Manoj

        Only order email is not working. Rest others are working fine. I have created new tamplates still not working.

        • mmpr

          Thanks a lot! this trick saved a few hours sleep tonight. After 8 hours, trying to fix this problem.

          • Giles (author)

            You’re welcome.

            Giles

  • nikunj

    i got this error ..
    Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() …. this code run on localhost…. plz help me

    • Giles (author)

      If by localhost you mean you’re running it on your own computer, then the chances are that you’re not running a mail server on port 25.

      Kind regards,

      Giles

  • Ashish

    Thanks ! It was very helpful and solved an email issue.

    • Giles (author)

      Ashish,

      Glad you found it useful.

      Kind regards,

      Giles

  • Vicky T

    Both the above scripts run as intended, mail is enable and email is also received when sent via script.
    For some reasone mails are not received when contact form is submitted. I just need contact form on my Magento 1.9.1 to work.
    Could you please point out what might be wrong with Magento here?

    • Giles (author)

      Vicky,

      The first paragraph of the post covers the most likely reason that emails aren’t being sent on Magento 1.9+.

      Kind regards,

      Giles

  • Mir

    There are many answers but none worked for me, How i solved is that,
    check that if your default template setup are theer in the magento or not.sometimes during installation its lost and actually “there is no email template by default in system to send you email”
    Please go to Admin side, System->Transactional Email->by default you will find np template here.So add by clicking on button ‘Add new Email templete ‘ .In ‘
    Load default template’ panel select a template from the Template dropdown suppose forgot Password and click and click ‘Load Template’. As earlier said no email template is associated with it so it will not be show in below. The bset thing is to go to install a fresh copy of magento in your local system navigate here and put that same content here and click Save Template button.
    Then go to System->Configuration->Customer Configuration ->Password Options->Change the ‘Forgot Email Template’ dropdown to yours as added above .Happy . thus same thing you can also do for order ,shipment,new Account etc.

  • Brian M

    Hi Giles
    I found the little test scripts useful to confirm the server’s mail is working properly.
    But my problem is the same as others – my client’s running Magento ver. 1.9.1.0 and it’s the Cron job that is “screwing up”.
    Plesk desk */5 * * * * php -q /dev/null /var/www/vhosts/dhsupport.com/httpdocs/cron.php
    I’ve got Order confirmation mails going to the customer, but not copied to admins.
    Any suggestion would be welcome
    Cheers
    Brian

    • Giles (author)

      Brian,

      If the emails are being sent to the clients, then they’re being sent to anyone who’s CC’d in on them, as it’s one and the same email – have they checked their spam bin? Have they got SPF records and DKIM in place?

      Kind regards,

      Giles

  • Ismo

    Hi,
    I test your script, and I had.

    mail() is enabled
    Sorry, your message could not be sent

    What can I do with that?
    In another dev site in the same server, I got
    mail() is enabled
    Your message has been sent successfully

    • Giles (author)

      Baradji,

      Try checking your PHP error log to see if there’s any indication why the mail was sent on one server and not on the other.

      Kind regards,

      Giles

  • John D

    Thanks for your scripts. I’m having issues with order confirmation emails sending in 1.9.1, contact form works and your scrips work.

    Still looking into it.

    • Menno V

      Did you find a solution to your problem? I have the exact same thing. Magento doesn’t sent any order confirmations. The scripts in the article work, the contact form and the new customer confirmation email are also still working.

      • kristian

        I got the same problem. Did you solve it?

      • Giles (author)

        If the customer confirmation and contact form emails are working, there’s no reason I can think of why the order confirmation, and only the order confirmation, emails wouldn’t work. Can you check the mail logs to see if it was sent? May be ending up in the recipient’s spam bin. If you’re using Magento 1.9.1, check that cron jobs are set to run properly?

        Kind regards,

        Giles

    • Martin

      In 1.9.1.0 the order emails are queued not immediately sent see App > Code > Core > Mage > Sales > Model > Order.php a new method queueNewOrderEmail() is now implemented in this class. These are then dispatched using the cron. Its not in 1.9.0 but is in 1.9.1 check your versions carefully.
      Hope this helps someone

      • Giles (author)

        Martin,

        A very good point, thanks for the comment.

        Kind regards,

        Giles

  • Pawan

    Hi Giles,

    I did both the tests, but for the second test i got 503 Error ( Service Unavailable) . Can you help me out with this?

    • Giles (author)

      I’d suggest checking your PHP error log to see why – it’s an unusual error to get if the first test has revealed that mail() is enabled.

      • Pawan

        I am pretty new to magento, so i am still getting the hold of magento. is there anyway i can contact you via email or chat?

        • Giles (author)

          Pawan,

          Details are on our contact page.

  • Lucky

    Both the above tests work successfully on my server but still my store is not sending any email to customers. no confirmation, no invoice, no shipment and nothing. In my mail sending settings, the host is set to localhost and port is to 25. not even i n spam folder.
    Thanks

    • Giles (author)

      Have you checked the mail logs to see if the outgoing emails are being sent and whether they are being delivered, or being bounced back?

      Giles

      • Lucky

        I have created this sales@mystore.com, info@mystore.com and support@mystore.com. I have done your both test with these accounts that I created and even with my gmail account also and I received mails everywhere (info, sales and support) but when I put my gmail account in your above script I got the mail in spam folder. but that is not an issue, the main thing is when I place a test order, I don’t receive any email. I am not getting mail of even password recovery when I click on forget Password. I am running my site on linux based shared hosting.

        Can you have a look, I can provide you my login credentials
        thanks!

        • Adnan

          How did you fix your issue, I am having the same issue. both tests given here passed but I am not able to received emails, however I receive contact us email but not any sales emails.

          • Adnan

            I was able to receive sales emails before.

          • Giles (author)

            If contact us emails are being sent to the same address as sales emails, then check your spam bin as a first step.

            Kind regards,

            Giles

  • Andrew

    When doing the second test, where should the email be sent from? The email was sent, but when looking at the details of the email (sent to a gmail account), it came from gmail which doesn’t match any email addresses we have set up in the admin to handle sales emails. It should be coming from our sales email via critsend. Is it possible the email sender is configured incorrectly somewhere else? I’m not sure what to make of this… Thanks for the tests, they really do help with the process of elimination.

    • Giles (author)

      Andrew,

      The email that’s sent isn’t sent by or through Magento, so whatever email addresses you’ve got set in the admin panel aren’t relevant – similarly, even though you may have configured Magento to use an SMTP relay (Critsend), this script won’t be using that. This is simply a test to see if your server is what’s stopping the emails being sent, or not – the email that it’s shown as coming from will be whatever you specify in the test.

      So if the test email is sent and received (check your spam bin, if you’re sending it to a Gmail account) but Magento itself isn’t sending emails, it’s most likely to be something in your SMTP configuration.

      Hope that helps,

      Kind regards,

      Giles

      • Giles (author)

        Andrew,

        You’re welcome – thanks for the suggestion.

        Kind regards,

        Giles

  • Kenneth

    “so at least you now know where best to start looking!”
    I was hoping the article could help me from here 😉 Thanks anyway…

    • Giles (author)

      Kenneth,

      Sorry if you didn’t find it helpful, or helpful enough, but unfortunately if it is down to server configuration, then there are so many possible causes that it would be impractical to cover them all – and in any event, the blog is concentrating primarily on issues with Magento not sending emails, rather than server-side issues.

      That said, if you’d like to get in touch on info@hummingbirduk.com, we may be able to help as we have a couple of server guys on our team.

      Giles

  • matdriks

    Next time i love to which magento version you use

    • Giles (author)

      Mat,

      The above should work on pretty much any Magento version.

      Giles

      • matdriks

        Giles,
        Do you have a tutorial to remove the emails from the spam bin.
        My e-mails are being sent to some people, but not all.
        Some of my costumers do not receive e-mails (order, invoice, password losts, etc.)
        Do you have experciene with this and do you know a solution.

        • Giles (author)

          Mat,

          Yes, there are a couple of steps you can take to reduce the likelihood that your emails end up in the spam bin – will try and cover them in a post later on this week.

          Giles

    • matdriks

      thx for the scripts. Now I know what the problem is.

Leave a Reply

Your email address will not be published. Required fields are marked *

Want to talk to us about your project?