PDA

View Full Version : Help With Sending A HTML Email


tomyknoker
04-16-2007, 04:53 AM
Can anyone help me with this code, I was just emailing text but it's becoming quit messy so thought I'd try and send it as a HTML, I have been able to format it and I can get a result from the top of the page, but how do I combine that with all my php & SQL Query?

<?php
mail('me@mydomain.com', 'Subject',
'<html><body><p>Your <i>message</i> here.</p></body></html>',
"To: The Receiver <me@mydomain.com>\n" .
"From: The Sender <sender@some.net>\n" .
"MIME-Version: 1.0\n" .
"Content-type: text/html; charset=iso-8859-1");


/* connect to the mysql database and use a query to get the members info */

include 'library/config.php';
include 'library/opendb.php';

$p = explode ( ' ', date('m Y') );

if ($p[0] == 1) {
$Month = 12;
$theYear = $p[1]-1;
}

else {
$Month = $p[0]-1;
$theYear = $p[1];
}

if ($Month < 10) {
$theMonth = '0'.$Month;
}

else {
$theMonth = $Month;
}

//$results = mysql_query("SELECT * FROM `tblmembers` WHERE `memberApproved` = 'P'");
$results = mysql_query("SELECT tblmembers.*, tblrepresentatives.rep_Firstname,tblrepresentatives.rep_Lastname FROM tblmembers LEFT JOIN tblrepresentatives ON (tblmembers.rep_NBR = tblrepresentatives.rep_NBR) WHERE tblmembers.memberApproved = 'P'");


if (mysql_num_rows($results) < 1) {
die('No members were approved last month');
}

else {

while ($qry = mysql_fetch_array($results)) {
if (strtotime($qry['loginDateTime']) <= (time() + 86400*31)) {
$login .= '<b> Name </b>' .$qry["FirstName"].' '.$qry["LastName"].'
Application Date:'.date("d/m/Y", strtotime($qry["JoinDate"])).' '.$qry["Email"].' '.$qry["rep_Firstname"].' '.$qry["rep_Lastname"].' ('.$qry["State"].')
--------------------
';
}
}

$message = <<<HERE
The login information is as follows:
-----------------------------------------

$login
HERE;

$from = "<me@mydomain.com>";

mail($to, $subject, $message, 'From: '.$from);
}

?>

cbsturg
05-15-2007, 02:29 AM
Off the top of my head, it looks like when you are instantiating the variable $message you are failing to put html code within it. That is, it should read something like $message = <<<HERE
The login information is as follows:<br />
-----------------------------------------<br /><br />

$login
HERE;

You could also write out all of the message content in normal text and then run a str_replace on the variable to put in <br /> tags wherever there's a new line carriage return

kbluhm
05-15-2007, 03:34 AM
You could also write out all of the message content in normal text and then run a str_replace on the variable to put in <br /> tags wherever there's a new line carriage return
Or just use nl2br() :cool:

cbsturg
05-15-2007, 03:39 AM
Or just use nl2br() :cool:
Sure, if you want to go with a more efficient solution... ;) After 5 years of programming in PHP, I'm still learning new tricks. One of these days, I'll decide to sit down and read every function that's available in PHP...