Sending mail from php

Most of the time when running a web server you will need to send mail from php applications. What happens if you don’t have sendmail on that machine or if you run apache in a chroot ?
Then you will need to send mail via smtp. And the best way is to use pear for this. It’s quite easy to change mail() with pear code:


$params[‘host’] = ‘’; // change this to your smtp server
$mail =& Mail::factory(‘smtp’, $params);
$headers = array(“From”=>”i@am.sender.of.mail”, “Subject”=>”Mail subject”);
$body = $msg;
$mail->send(“”, $headers, $body);

Installing the necessary pear classes is done like this:

pear install Mail
pear install Net_SMTP

Happy mail sending.

2 thoughts on “Sending mail from php

Comments are closed.