Send HTML email Using SMTP Authentication

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
basil_al_dajane
Forum Newbie
Posts: 1
Joined: Fri Nov 14, 2008 8:11 am

Send HTML email Using SMTP Authentication

Post by basil_al_dajane »

I have the code for sending SMTP authenticated emails
But it only sends plain text email, what should I change in my code to get it to send html emails

Code:

Code: Select all

<?php
require_once "Mail.php";
 
$from = "<name@localhost.com>";
$to = "<recp@otherhost.com>";
$subject = "Subject";
$body = "HTML Body";
 
$host = "localhost";
$username = "name@localhost.com";
$password = "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>");
}
?>
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Re: Send HTML email Using SMTP Authentication

Post by aaronhall »

Googling "php send html email" should return some answers
Post Reply