Skip to content

Sending mail from php

  • by

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:

include(‘Mail.php’);

$params[‘host’] = ‘127.0.0.1’; // 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(“destinatar@destinatar.domain.name”, $headers, $body);

Installing the necessary pear classes is done like this:

pear install Mail
pear install Net_SMTP

Happy mail sending.

Tags:

2 thoughts on “Sending mail from php”

Comments are closed.