/    Sign up×
Community /Pin to ProfileBookmark

We are trying to produce an email that will be sent in HTML. Right now, the email is successfully delivered in plain text with all the tags displayed. I know there has to be a simple solution. Does the solution lie within these tags?

[code]
$htmlHeader = “<HTML><BODY><HEAD><META HTTP-EQUIV=”Content-Type” CONTENT=”text/html; charset=us-ascii”></HEAD>”;
$text = “n<p>” . stripslashes($text) . “n</p>”;
$htmlFooter = “</BODY></HTML>”;
[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@GenixdeaeMar 09.2005 — http://us3.php.net/manual/en/function.mail.php

that'll let you know anything you need to

if you scroll down it says

[code=php]// 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";[/code]


hope that helps

make sure you have mail(from, to, message, title, headers); where headers are is where you put the mime-version and content type. not in the message.
Copy linkTweet thisAlerts:
@MarySunshineauthorMar 11.2005 — We are stumped. Can someone take a look at this code and let me know if you can figure out what we've done wrong. The emails are delivered in plain text with all the HTML coding displayed as well as the correct db output.
[code=php]
<HTML>
<HEAD>
</HEAD>

<BODY>
<?php
require("./../../adodb/adodb.inc.php");
require("./../../Connections/ssc.php");
require_once 'Mail.php';

@extract($_POST);

// Validate the email addresses
$validEmailExpr = "(0-9a-z~!#$%&_-.)*@(0-9a-z~!#$%&_-.)*";
if (empty($to) || empty ($from) || !eregi($validEmailExpr, $to) || !eregi($validEmailExpr, $from))
header("location:./wishlistEmail.php?Account=" . $Account . "&consultantID=" . $consultantID
. "&Error=Email");

// Save the user (Account)'s email address ($from) to the DB.
$sql = "UPDATE Account SET Email="" . $from . """
. " WHERE AccountID=" . $Account;
$rst=$ssc->Execute($sql) or DIE($ssc->ErrorMsg());


// Retrieve the Wishlist books from the DB.
$bookSql = "SELECT A.AccountID, BookID, SeriesID, Quantity, ISBN, Title, Price/100 as Price
FROM Account A, WishlistBook W
WHERE A.AccountID = W.AccountID
AND A.AccountID = " . $Account
. " ORDER BY Title ASC";
$rst=$ssc->Execute($bookSql) or DIE($ssc->ErrorMsg());

// Start the Email report table with column headers
$report = sprintf("%s", "<br>"
. "n<table>"
. "n<tr>"
. "nt<td>Quantity</td>"
. "nt<td>Title</td>"
. "nt<td>ISBN</td>"
. "nt<td>In Stock</td>"
. "nt<td>Price</td>"
. "n</tr>");
$report .= sprintf("%s", "n<tr><td><sp></td></tr>");

// Read and display each record from the query to the Email Report.
$rst->moveFirst();
while (!$rst->EOF)
{
$Book = $rst->Fields("BookID");
$Title = $rst->Fields("Title");

$report .= sprintf("%s", "n<tr>");
$report .= sprintf("%s", "nt<td>".$rst->Fields("Quantity")."</td>");
$report .= sprintf("%s", "nt<td>".$Title."</td>");
$report .= sprintf("%s", "nt<td>".$rst->Fields("ISBN")."</td>");

// Find out if Book is "in stock" (in current catalog).
$sql = "SELECT bookID FROM Book WHERE bookID=" . $Book;
$rstBook = $ssc->Execute($sql) or DIE($ssc->ErrorMsg());
if ($rstBook->EOF) // Book is NOT in current catalog
{
$sql = "SELECT * FROM Book WHERE title ="" . $Title . """;
$rstBook = $ssc->Execute($sql) or DIE($ssc->ErrorMsg());
if ($rstBook->EOF) // No Book in current catalog with the same title.
{ $report .= sprintf("%s", "nt<td>No</td>"); }
else
{ $report .= sprintf("%s", "nt<td>Maybe</td>"); }
}
else
{ $report .= sprintf("%s", "nt<td>Yes</td>"); }

$report .= sprintf("%s", "nt<td>".$rst->Fields("Price")."</td>");
$report .= sprintf("%s", "n</tr>");
$rst->moveNext();
}
$report .= sprintf("%s", "n</table>n");

// Send the Email Report (in HTML format).
$subject = "My Usborne Wishlist";

$htmlHeader = "<HTML><BODY>";
$text = "n<p>" . stripslashes($text) . "n</p>";
$htmlFooter = "</BODY></HTML>";
$contents = $htmlHeader.$name.$phonenumber.$text.$report.$htmlFooter;

// $headers = array
// (
// 'From' => $from
// ,'To' => $to
// ,'Subject' => $subject
// ,'MIME-Version' => '1.0'
// ,'Content-type' => 'text/html; charset=iso-8859-1'
// );

// $mailer =& Mail::factory('sendmail');
//print "mailer.send($to, var_dump($headers), $contents);";
//var_dump($headers);
// $result = $mailer->send($to, $headers, $contents);
// print "nResult is $result.n";


$msgHeader = 'From: ' . $from . "rn";
$msgHeader .= 'MIME-Version: 1.0' . "rn";
$msgHeader .= 'Content-type: text/plain; charset=us-ascii' . "rn";
// print "mail($to, $subject, $contents, $msgHeader);";
mail($to, $subject, $contents, $msgHeader);

// Return to the Wishlist page.
header("location:./wishlistView.php?consultantID=" . $consultantID);
?>
</BODY>
</HTML>




[/code]
Copy linkTweet thisAlerts:
@mikkoMar 11.2005 — And setting the content type to text/html, as already suggested, didn't help?

[code=php]$msgHeader = 'From: ' . $from . "rn";
$msgHeader .= 'MIME-Version: 1.0' . "rn";
$msgHeader .= 'Content-type: text/html; charset=iso-8859-1' . "rn"; [/code]
Copy linkTweet thisAlerts:
@MarySunshineauthorMar 11.2005 — sadly, no ?
Copy linkTweet thisAlerts:
@bokehMar 12.2005 — Hi! The following is a bit of working code that sends HTML email. Maybe it will help you find your fault. Save your email as a file and check it with a text editor then do the same with this script and see what the difference is. This should point you in the right direction to find out what is wrong with your script.
[code=php]
<?php
$content = 'your content here';

$message = "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" n" .
" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> n" .
"<html xmlns="http://www.w3.org/1999/xhtml"> n" .
"<head> n" .
" <meta http-equiv="content-type" content= n" .
" "text/html; charset=iso-8859-1" /> n" .
"<style> n" .
"body { font-size: 9pt; font-family: verdana, sans-serif; color: #000; background:#fff; } n" .
".bold { font-weight: bold; } n" .
"</style> n" .
"</head> n" .
"<body>$content n" .
"</body> n" .
"</html> nn";

$to = 'to@some_email.tld';
$from = 'from@some_email.tld';

$headers = "From: $from";

// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// Add the headers for a file attachment
$headers .= "nMIME-Version: 1.0n" .
"Content-Type: multipart/mixed;n" .
" boundary="{$mime_boundary}"";

// Add a multipart boundary above the html message
$message = "This is a multi-part message in MIME format.nn" .
"--{$mime_boundary}n" .
"Content-Type: text/html; charset="iso-8859-1"n" .
"Content-Transfer-Encoding: 7bitnn" .
$message . "nn";
}

// Send the message
mail($to, $subject, $message, $headers);

?>
[/code]
×

Success!

Help @MarySunshine 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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