Pear SMTP Authentication


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:

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.



Article ID: 1866
Created On: Wed, Nov 17, 2021 at 3:19 PM
Last Updated On: Wed, Nov 17, 2021 at 3:22 PM

Online URL: https://www.heartinternet.uk/support/article/pear-smtp-authentication.html