I was working on a project and needed to send mails via php using an SMTP server.   It seems that Fedora doesn’t have this built in when I installed my linux box.  So anyway, for those people who are searching for information on how to send mail from php via SMTP, below are the steps.
Step # 1: Download Pear Packages for Mail, Net_SMTP, and Net_Socket
# cd /tmp
# wget http://download.pear.php.net/package/Mail-1.1.14.tgz
# wget http://download.pear.php.net/package/Net_SMTP-1.2.10.tgz
# wget http://download.pear.php.net/package/Net_Socket-1.0.8.tgz
Untar all files:
# tar -zxvf Mail-1.1.14.tgz
# tar -zxvf Net_SMTP-1.2.10.tgz
# tar -zxvf Net_Socket-1.0.8.tgz
Step#2:Â Copy the files to /usr/share/pear
# cd /usr/share/pear
# mkdir Net
# cd Net
# cp /tmp/Net_SMTP-1.2.10/SMTP.php .
# cp /tmp/Net_Socket-1.0.8/Socket.php .
# cd ..
# cp -avr /tmp/Mail-1.1.14/Mail/ .
# cp -avr /tmp/Mail-1.1.14/Mail.php .
You’re Done!
Now to test, try this small php program.
include("Mail.php");
/* mail setup recipients, subject etc */
$recipients = "yournamehere@domain.com";
$headers["From"] = “from@yourdomain.com”;
$headers["To"] = “receipient@theirdomain.com”;
$headers["Subject"] = “test via smtp”;
$mailmsg = “Hello, This is a test.”;
/* SMTP server name, port, user/passwd */
$smtpinfo["host"] = “smtp.yourserver.com”;
$smtpinfo["port"] = “25″;
$smtpinfo["auth"] = true;
$smtpinfo["username"] = “test”;
$smtpinfo["password"] = “test”;
/* Create the mail object using the Mail::factory method */
$mail_object =& Mail::factory(”smtp”, $smtpinfo);
/* Ok send mail */
$mail_object->send($recipients, $headers, $mailmsg);
?>
Now check your email and see if it worked!
Best Deal Ads :





