0

i have this PHP Code/function to send emails.

what code do i need to add to make the emails that get sent HTML rather than plain Text?

function sendemail($email_to,$email_from,$email_subject,$email_body,$email_replyto)
    {
        require_once "/usr/local/lib/php/Mail.php";

        $from = $email_from;
        $to = $email_to;
        $subject = $email_subject;
        $body = $email_body;

        $host = "mail.integradigital.co.uk";
        $username = "[email protected]";
        $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>");
         }
    }
0

3 Answers 3

1

add "Content-Type: text/html; charset=ISO-8859-1\r\n"; to your headers.

0
<?php
// multiple recipients
$to  = '[email protected]' . ', '; // note the comma
$to .= '[email protected]';

// subject
$subject = 'Birthday Reminders for August';

// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>

Refer the link http://php.net/manual/en/function.mail.php

0

You'd be better off using the Mail_Mime package which will allow you to send both HTML and plain text e-mails easily:-

$mime = new Mail_mime();
$mime->setTXTBody($text);
$mime->setHTMLBody($html);

Here's a good example from the documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.