Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems
Jazzing up PHP Emails!

Posted by seandosh (seandosh), 29 October 2003
I have no problems mailing from a server using PHP but does anyone know how I can make the content more graphical i.e how to change the font adding images, links etc...

I figured if I wrote the body of the email using just plain old html MS Outlook and the like would pick up on this  but instead it just displayed the code in the body of the email.

I'm simply using the following code to send the email.

if (mail("$email",
     "")) {
     echo "<br>mail sent to ";
     echo $name;
     echo"<br><br><b>Thank you!</b>";
     } else {
     print "FAILURE!";


Is their another function I need to use? If anyone can shed any light on this i'd be very grateful!


Posted by Custard (Custard), 29 October 2003

Perhaps you need a Content-Type: text/html header in the mail.

Most of the HTML emails I've seen contain MIME entities, one of which is text (Content-Type: text/plain) and one of text/html.

I don't know php very well, but I'd start by looking for things to do with MIME.



Posted by John_Moylan (jfp), 30 October 2003
Pear can help here with Mail_mime.

This can send text, html and attachemnts.
I use this one on the command line.

#! /opt/php-4.3/bin/php



$file = 'attach.txt';
$htmlFilename = "htmlFile.html";
$textFilename = "textFile.txt";

// html version
$FH = fopen ($htmlFilename, "r");
   $html = fread ($FH, filesize ($htmlFilename));
fclose ($FH);

// text version
$FH2 = fopen ($textFilename, "r");
   $text = fread ($FH2, filesize ($textFilename));
fclose ($FH2);

$crlf = "\r\n"; // lined endings
$hdrs = array('From'     => 'SENDER <>',
             'Subject'  => 'Any old iron',
             'REPLY-TO' => '');

$mime = new Mail_mime($crlf);

$mime->addAttachment($file, 'text/plain');

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

$mail =& Mail::factory('mail');

// Do a dblookup for emails here, or just make an array as I've done
$emailAry = array('', '');

foreach ($emailAry as $address) {

   $mail->send($address, $hdrs, $body);


This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: • WEB: • SKYPE: wellho