Sending E-mails with PHP
August 7, 2007 6:57 AM   Subscribe

How do I get PHP to send an e-mail. Is there a way to do it without recompiling PHP/Apache. If not, how do I recompile PHP/Apache on a linux system to do this?

How do I get PHP to send an e-mail. Is there a way to do it without recompiling PHP/Apache. If not, how do I recompile PHP/Apache on a linux system to do this?

Ideally, I would like to find a way without recompiling my software, but if there is not other way, I can recompile the software.
posted by kaozity to Computers & Internet (11 answers total)
 
if (mail($to, $messageSubject, $messageBody, $messageHeaders))
{
   echo "success!";
}
else
{
   echo "message delivery failed";
}

posted by Blazecock Pileon at 7:01 AM on August 7, 2007


or use a library like this one (don't know if its any good)
posted by uandt at 7:04 AM on August 7, 2007


Response by poster: the mail() function gives message delivery failed.. perhaps i am not using it correctly?

The library gives me an error.
posted by kaozity at 7:21 AM on August 7, 2007


Did you check the requirements in the mail documentation? Do you have sendmail or another MTA installed and accessible to PHP? You may also need to edit the php.ini file.

What error does the Xpertmailer library return?
posted by Blazecock Pileon at 7:24 AM on August 7, 2007


Response by poster:
Error: invalid connection type on MAIL5->send()
posted by kaozity at 7:27 AM on August 7, 2007


I would recommend that you read the requirements for running mail and make sure you have sendmail or another MTA installed.
posted by Blazecock Pileon at 7:31 AM on August 7, 2007


So, I'm assuming you are not using a Windows system (but if you are you can set the mail settings in the php.ini file) and as Blazecock Pileon suggests you need to have an MTA like sendmail installed. If you don't want to have this installed, I have used ssmtp in the past and it works very well. It is acts in place of sendmail and just sends the mail off to your real mail server for delivery. Otherwise, read the fine manual about mail()'s requirements and make sure they are met. There is no recompiling needed.
posted by chrisroberts at 7:37 AM on August 7, 2007


PHPmailer.
posted by brownpau at 7:43 AM on August 7, 2007


PHP's mail() implementation is naive and not particularly good. There are excellent third-party libraries that can not only re-implement everything mail() does but do it well. We use SwiftMailer, but there are others.

I strongly suggest you take the time now to setup an external SMTP server and do all your sending via that, rather than relying on whatever your host's sendmail command does. This will make portability and debugging substantially easier.
posted by Skorgu at 9:59 AM on August 7, 2007


I also strongly, strongly, STRONGLY recommend that if you don't know what the terms "code injection" or "cross-site scripting" mean, then you stop this project now and find something that you can be guaranteed is bulletproof in terms of being able to (a) send mail reliably, without (b) allowing hackers and spammers to find entrypoints into your system and/or the mail system at large. In my estimation (and many others'), homegrown mailing systems like these provide a huge, huge, huge opportunity for hackers to figure out ways to compromise your mail server, and provide similar abilities for spammers to usurp your unsuspecting mail script to send out hundreds of thousands of spam messages a day.
posted by delfuego at 10:29 AM on August 7, 2007 [2 favorites]


For more info, see:

here
here
here
here

and a jillion other places out there.
posted by delfuego at 10:31 AM on August 7, 2007


« Older Bubbles   |   A Zoltant Khodaly choral work with a Hallelujah at... Newer »
This thread is closed to new comments.