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
 
For 2023 - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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",
      "$title",
      "$text",
     "From:email@email.co.uk")) {
     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!

Sean.

Posted by Custard (Custard), 29 October 2003
Hello,

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.

hth

Bruce

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.

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

<?php

include('Mail.php');
include('Mail/mime.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 <me@this.com>',
             'Subject'  => 'Any old iron',
             'REPLY-TO' => 'reply@to_me.com');

$mime = new Mail_mime($crlf);

$mime->setHTMLBody($html);
$mime->setTXTBody($text);
$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('this@that.com', 'that@this.com');

foreach ($emailAry as $address) {

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


jfp



This page is a thread posted to the opentalk forum at www.opentalk.org.uk 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., 2023: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho