Sending mail through PHP

From Wiki
Jump to: navigation, search

The pear Mail class can be used to send mail using external SMTP servers. Here is a simple test script to do this.

// Pear Mail Library
require_once "Mail.php";

$from = '<>'; //change this to your email address
$to = '<>'; // change to address
$subject = 'Test Message'; // subject of mail
$body = "Hello world! this is the content of the email"; //content of mail

$headers = array('From' => $from, 'To' => $to, 'Subject' => $subject);

$smtp = Mail::factory('smtp', array('host' => 'ssl://', 'port' => '587', 'auth' => true, 'username' => 'username', 'password' => 'password'));

//Send the mail
$mail = $smtp->send($to, $headers, $body);