/    Sign up×
Community /Pin to ProfileBookmark

Help With Sending A HTML Email

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?

[code=php]<?php
mail(‘[email protected]’, ‘Subject’,
‘<html><body><p>Your <i>message</i> here.</p></body></html>’,
“To: The Receiver <[email protected]>n” .
“From: The Sender <[email protected]>n” .
“MIME-Version: 1.0n” .
“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 = “<[email protected]>”;

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

?>[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@mahfoozApr 16.2007 — http://www.php.net/manual/en/ref.mail.php

you should use some extra headers as on this manual use as:

[code=php]
$body="<em>HTML</em> formatted <strong>Message</strong";

$headers = "From: [email protected] rn";
$headers.= "Content-Type: text/html; charset=ISO-8859-1 ";
$headers .= "MIME-Version: 1.0 ";
/*notice there aren't any rn after the second two header additions. This is what made this version work correctly*/
mail("[email protected]", "An HTML Message", $body, $headers);
[/code]
Copy linkTweet thisAlerts:
@nihaApr 16.2007 — try this it worked for me

$email="[email protected]";

$sender_address= "[email protected]";

// To send HTML mail, the Content-type header must be set

$headers = 'MIME-Version: 1.0' . "rn";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";

$headers .= 'Return-Path: ' . $sender_address . "n";

$headers .= ' bcc: [email][email protected][/email]';

mail("$email","the subject here","$emailmsg","$headers");
[/QUOTE]
×

Success!

Help @tomyknoker spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...