Send mail via Pear Mail for Linux

This article will go over sending mail from your Linux server using Pear Mail. It is recommended to use Pear Mail over sendmail for Linux as it is more reliable (it authenticates with SmarterMail) and there is better tracking and logging for any delivery issues that arise.

Note: Prior to using Pear Mail properly, you will need to contact support to set up the prerequisites for your account.

  1. Log into the Linux server via SSH [Mac | Windows] or via FTP.
  2. Create a file with the content as follows:
  3. <?php

    require_once "Mail.php";

    $from = "Some Sender <sender@domain.com>";

    $to = "Some Recipient <recipient@domain.com>";

    $subject = "Your Subject Here";

    $body = "Body Text Goes Here";

    $host = "mail.domain.com";

    $username = "smtp_username";

    $password = "smtp_password";

    $headers = array ('From' => $from,

    'To' => $to,

    'Subject' => $subject);

    $smtp = Mail::factory('smtp',

    array ('host' => $host,

    '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>");

    }

    ?>

  4. In the $from line, enter in your email address as it is setup on the SmarterMail server. This will be the sender's email address.
  5. In the $to line, enter in the recipient's email address.
  6. Change the $subject line to the subject of your message and the $body to the message body text.
  7. Next, change the $host to your mail server (typically mail.yourdomain.com), the $username to your full email address as setup in SmarterMail, and $password which is your user password for the email address in SmarterMail. The rest of the script can be left as is.
  8. Now when you send a message via this script, it will authenticate via the mail server rather than just sending via sendmail on the Linux server. This ensures greater reliability and tracking should an issue arise in the future with a specific email.