Prev | Current Page 485 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"


Despite the widespread confusion surrounding this task, sending an HTMLformatted
e-mail is actually quite easy. Consider Listing 16-2, which creates and sends
an HTML-formatted message.
416 CHAPTER 16 ?–  NE TWORKING
Listing 16-2. Sending an HTML-Formatted E-mail
// Include the Mail and Mime_Mail Packages
include('Mail.php');
include('Mail/mime.php');
// Recipient Name and E-mail Address
$name = "Jason Gilmore";
$recipient = "jason@example.org";
// Sender Address
$from = "bram@example.com";
// Message Subject
$subject = "Thank you for your inquiry - HTML Format";
// E-mail Body
$html = <<

Example.com Stamp Company



Dear $name,

Thank you for your interest in Example.com's fine selection of
collectible stamps. Please respond at your convenience with your telephone
number and a suggested date and time to chat.


I look forward to hearing from you.



Sincerely,

Bram Brownstein

President, Example.com Stamp Supply
html;
// Identify the Relevant Mail Headers
$headers['From'] = $from;
$headers['Subject'] = $subject;
CHAPTER 16 ?–  NETWORKING 417
// Instantiate Mail_mime Class
$mimemail = new Mail_mime();
// Set HTML Message
$mimemail->setHTMLBody($html);
// Build Message
$message = $mimemail->get();
// Prepare the Headers
$mailheaders = $mimemail->headers($headers);
// Create New Instance of Mail Class
$email =& Mail::factory('mail');
// Send the E-mail Already!
$email->send($recipient, $mailheaders, $message) or die("Can't send
message!");
?>
Executing this script results in an e-mail that looks like that shown in Figure 16-1.


Pages:
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497