Pear: Mail

Discussion in 'PHP' started by cancer10, Feb 6, 2009.

  1. #1
    Hi

    Would anyone know how to send an email with content type = text/html with the following code?


    <?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);
    
    if (PEAR::isError($mail)) {
      echo("<p>" . $mail->getMessage() . "</p>");
     } else {
      echo("<p>Message successfully sent!</p>");
     }
    ?>
    Code (markup):

    Source:
    http://email.about.com/od/emailprogrammingtips/qt/et073006.htm



    Thanx
     
    cancer10, Feb 6, 2009 IP