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.

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

$from = '<user@example.com>'; //change this to your email address
$to = '<user2@example.com>'; // 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://smtp.example.com', 'port' => '587', 'auth' => true, 'username' => 'username', 'password' => 'password'));

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