Pear Mail SMTP Authentication
This article will cover the code and requirements for using a Pear mail script to send SMTP authenticated emails from your website.
Pear Requirements
Pear mail will require you to have the following settings ready to enter into the mail script:
- The username of the mailbox you are connecting to and sending from.
- The password of the mailbox you are sending from.
- The mail server that hosts your mailbox.
- The port number you are connecting on.
Send Mail Script
This is the actual script that will need adding to your website, it will need to appropriate sections editing to your specific settings or requirements.
<?php
require_once "/usr/share/pear7/Mail.php";
$from = "Your Name <Your Email Address>";
$to = "Recipient's Name <Recipients Email Address>";
$subject = " Enter Subject Here ";
$body = " This is the main content of your email ";
$host = "ssl://Your mail server";
$port = "465 (or the port specified by your mail provider)";
$username = "Your Mailbox Username";
$password = "Your Mailbox Password";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
This script can be added to your site as a standalone sending script or it can be integrated into a function that requires sending mail such as a contact form.





 Print Article
Print Article Email Article to Friend
Email Article to Friend Export to PDF
Export to PDF