I have a custom module that sends email on localhost but now when I uploaded it to a live server, it generates an exception saying that "Unable to send mail."

Note: emails are enabled on the server and it sends registration or other emails. I think it is not a duplicate question as in this: Magento e-mail sending does not work question email never got delivered. where as in my case registration/order emails are successfully delivering.

  • in my case, it is working on localhost but not on hosted server. also emails are enabled on server as i can receive other transaction emails
    – Haris
    Sep 2, 2014 at 12:53
  • 1
    You may need to call your hosting company, some hosting company have special method send email inorder to combat spam on there server Sep 2, 2014 at 12:55
  • 1
    It may of course also be an issue how you implement the mail sending functionality, but in order to check that you have to show us the code.
    – Simon
    Sep 4, 2014 at 12:58
  • @Simon before i was using some other code, but now using code given in the #DanHanly Answer, but same problem, sending email successfully on localhost but not on server.
    – Haris
    Sep 8, 2014 at 9:33

1 Answer 1


Are you using the Email sending classes?

If not, try doing it this way, as this will give you the flexibility of outputting an error message when the message is sent. Using both Mage::log and Session based error output will allow you to see what's going on even if you don't witness the event.

$mail = Mage::getModel('core/email')
        ->setSubject('Subject :')

} catch(Exception $error) {
    return false;

Failing this, it's probably something you'll need to speak to your hosting company about, as they sometimes block certain mail methods.


Not the answer you're looking for? Browse other questions tagged or ask your own question.