How to send an email using Zend_Mail, sendmail, and localhost?
Asked Answered
N

2

8

I'm developing a zend framework application that includes a simple email function. The development version is running on my computer, which is running Ubuntu. The production version is going to run on a production server.

When trying to send a test email to myself, I get an exception with the message: "Unable to send mail". I don't know if this is an environment issue, or a code issue. I'm not using a transport so I think it is defaulting to Zend_Mail_Transport_Sendmail. Here's my code:

public function sendtestAction()
{
    $mail = new Zend_Mail();
    $mail->setFrom('[email protected]', 'Test Email');
    $mail->addTo('[email protected]', 'My Name');
    $mail->setSubject('This is just a test.');
    $mail->setBodyText('This is only a test.');
    $mail->send();
}

Update: I tried a different approach by setting the SMTP transport to use localhost:

transport = new Zend_Mail_Transport_Smtp('localhost');
Zend_Mail::setDefaultTransport($transport); 

I got a different error this time: "Connection refused" Not sure what that means. Maybe I haven't set something up yet?

Update: I guess I didn't have an SMTP server installed/setup. This tutorial made it really easy for me to get an SMTP server up an running. Now both of the code samples above work.

Naamana answered 27/10, 2009 at 22:51 Comment(5)
Do your smtp logs show anything?Cacique
Looks like there is no SMTP deamon on server you're using. Or it's not configured to use default portAeolotropic
in /var/log/ I opened mail.err, mail.info, mail.log, mail.warn but they were empty. Also, mail was the closest thing I could find to a log. There wasn't any smtp or sendmail logs or directoriesNaamana
Try telnet'ing to port 25 of localhost. What happens?Hiram
Sorry, I don't know anything about "telnet'ing"Naamana
O
2

It sounds like you need to configure an MTA, or find one that you can send to. Ubuntu desktop should set one up by default, probably either exim or postfix, but if you haven't configured it, it will unlikely to be running.

Occupier answered 28/10, 2009 at 0:2 Comment(0)
E
2

You don't want to set the default transport if you wish to use sendmail (it is the default) and SMTP is different.

That it doesn't send the emails suggests that sendmail or the MTA on your server is not installed/not setup correctly.

Excepting answered 28/10, 2009 at 0:1 Comment(0)
O
2

It sounds like you need to configure an MTA, or find one that you can send to. Ubuntu desktop should set one up by default, probably either exim or postfix, but if you haven't configured it, it will unlikely to be running.

Occupier answered 28/10, 2009 at 0:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.