0

How would I adapt this answer and combine it with to allow me to send HTML mail? I've got pear mail_mime, and I've heard that's something to do with it. Here's the code I've gotten so far but it is not working:

require 'Mail.php';
require 'Mail/mime.php';

    $userID = 13;

    $realname = getRealName($userID); //This function works

    require_once "mail_register.php"; // Includes $register_body_txt and $register_body_html

    $subject = "DERP YAY SENT EMAIL!";
    $to = '<myemail@me.com>';

    $from = "Derp <noreply@derp.com>";
    $host = "ssl://smtp.gmail.com";
    $port = "465";
    $username = "noreply@derp.com";
    $password = "password";

    $crlf = '\n';

    $headers = array (
            'From'          => $from,
            'Subject'       => $subject,
            'Return-Path'   => $from);

    $mime = new Mail_mime(array('eol' => $crlf));

    $mime->setTXTBody($register_body_txt);
    $mime->setHTMLBody($register_body_html);

    $body = $mime->get();
    $headers = $mime->headers($headers);

    $mail =& Mail::factory('mail');
    $mail->send($to, $headers, $body);

    if (PEAR::isError($mail)) { //This is no longer working. Before I adapted the previous script, it would show me actual errors instead of printing out successful all the time.
      echo("<p>" . $mail->getMessage() . "</p>");
    } else {
      echo("<p>Message successfully sent!</p>");
    }
Community
  • 1
  • 1
Alfo
  • 4,801
  • 9
  • 38
  • 51
  • I have tried that, but could not get it to fit neatly into the script above. It apparently uses $mime as an object, which I do not understand. And please refer to: http://meta.stackexchange.com/questions/8724/how-should-we-deal-with-google-questions – Alfo Jul 24 '12 at 14:51
  • 1
    @AlexHowansky: lmgtfy is banned on Stack Overflow, please do not circumvent this ban through a url shortener. – ThiefMaster Jul 27 '12 at 13:30
  • I've added some code that I'm using now. – Alfo Jul 28 '12 at 12:17

0 Answers0