Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. Send Email in HTML Format

Send Email in HTML Format

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
phphtmlcomdata-structureshelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    awedaonline
    wrote on last edited by
    #1

    Hello guys, I want to be able to send mail in html format like the one below but I get the raw html in my mail.

    include_once "Mail.php";

    function isMailSent($from, $to, $subject, $body) {

    $host = "mail.domain.com";
    $username = "email@domain.com";
    $password = "password";

    $headers = array ('From' => $from,
    'To' => $to,
    'Subject' => $subject);

    $smtp = Mail::factory('smtp',
    array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));
    try {

    // add to the body
    $body = '

    ' . $body . '

    Thank you!

    ';

    // dispathc mail
    $mail = $smtp->send($to, $headers, $body);

    // check if mail was sent successfully
    if (PEAR::isError($mail)) {
    return "

    " . $mail->getMessage() . "

    ";
    } else {
    return "

    Message successfully sent!

    ";
    }

    } catch (Exception $e) {
    return $e->getMessage();
    }
    }

    Please help.

    J 1 Reply Last reply
    0
    • A awedaonline

      Hello guys, I want to be able to send mail in html format like the one below but I get the raw html in my mail.

      include_once "Mail.php";

      function isMailSent($from, $to, $subject, $body) {

      $host = "mail.domain.com";
      $username = "email@domain.com";
      $password = "password";

      $headers = array ('From' => $from,
      'To' => $to,
      'Subject' => $subject);

      $smtp = Mail::factory('smtp',
      array ('host' => $host,
      'auth' => true,
      'username' => $username,
      'password' => $password));
      try {

      // add to the body
      $body = '

      ' . $body . '

      Thank you!

      ';

      // dispathc mail
      $mail = $smtp->send($to, $headers, $body);

      // check if mail was sent successfully
      if (PEAR::isError($mail)) {
      return "

      " . $mail->getMessage() . "

      ";
      } else {
      return "

      Message successfully sent!

      ";
      }

      } catch (Exception $e) {
      return $e->getMessage();
      }
      }

      Please help.

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      I don't know much about PHP, but you must pass the proper content type in the mail header (adjust the charset and encoding if necessary, e.g. charset us-ascii with encoding 7bit):

      $headers['Content-Type'] = "text/html; charset=\"UTF-8\"";
      $headers['Content-Transfer-Encoding'] = "8bit";

      A 1 Reply Last reply
      0
      • J Jochen Arndt

        I don't know much about PHP, but you must pass the proper content type in the mail header (adjust the charset and encoding if necessary, e.g. charset us-ascii with encoding 7bit):

        $headers['Content-Type'] = "text/html; charset=\"UTF-8\"";
        $headers['Content-Transfer-Encoding'] = "8bit";

        A Offline
        A Offline
        awedaonline
        wrote on last edited by
        #3

        Thanks a million. I will do what you said!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups