john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

php PEAR smtp authentication

php-using-PEAR-and-smtp-authentication

<?php
    require_once "Mail.php";

    $from = "Sandra Sender <sender@example.com>";
    $to = "Ramona Recipient <recipient@example.com>";
    $subject = "Hi!";
    $body = "Hi,\n\nHow are you?";

    $host = "mail.example.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);

//note that this uses the PEAR email MTA...

    if (PEAR::isError($mail)) {
      echo("<p>" . $mail->getMessage() . "</p>");
     } else {
      echo("<p>Message successfully sent!</p>");
     }


?>

  • « php file insert
  • php multi button form »

Published

Feb 6, 2010

Category

php

~72 words

Tags

  • authentication 4
  • pear 2
  • php 82
  • smtp 3