need help displaying html in emails

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
darkfreaks
Forum Commoner
Posts: 59
Joined: Sat Sep 09, 2006 3:59 pm

need help displaying html in emails

Post by darkfreaks »

ok my email order form works perfectly but when it sends the email to any adress in the message it shows the html tag code instead of displaying it is there anyway this can be fixed?

Code: Select all


[syntax=php]} else {

$NNSQTY = $_POST[NNSQTY];
$CBFNQTY = $_POST[CBFNQTY];
$AKNQTY = $_POST[AKNQTY];
$CFNQTY = $_POST[CFNQTY];
$CVNQTY = $_POST[CVNQTY];
$name = $_POST[ordername];
$email = $_POST[email];
$email = $_POST[email];
$name = $_POST[name] ;
$NNSBT = $_POST[NNSBT];
$CBFNBT = $_POST[CBFNBT];
$AKNBT = $_POST[AKNBT];
$CFNBT = $_POST[CFNBT];
$CVNBT = $_POST[CVNBT];
$NNS_size = $_POST[NNS_size];
$CBFN_size = $_POST[CBFN_size];
$AKN_size = $_POST[AKN_size];
$CFN_size = $_POST[CFN_size];
$CVN_size = $_POST[CVN_size];
$NNSBS = $_POST[NNSBS];
$CBFNBS = $_POST[CBFNBS];
$AKNBS = $_POST[AKNBS];
$CFNBS = $_POST[CFNBS];
$CVNBS = $_POST[CVNBS];
$NNSBC = $_POST[NNSBC];
$CBFNBC = $_POST[CBFNBC];
$AKNBC = $_POST[AKNBC];
$CFNBC = $_POST[CFNBC];
$CVNBC = $_POST[CVNBC];
$NNSP = $_POST[NNSP];
$CBFNP = $_POST[CBFNP];
$AKNP = $_POST[AKNP];
$CFNP = $_POST[CFNP];
$CVNP = $_POST[CVNP];
$NNSL = $_POST[NNSL];
$CBFNL = $_POST[CBFNL];
$AKNL = $_POST[AKNL];
$CFNL = $_POST[CFNL];
$CVNL = $_POST[CVNL];
//define

$NNPRICE = $NNSQTY * 50;
$CBFPRICE = $CBFNQTY * 50;
$AKNPRICE = $AKNQTY * 30;
$CFNPRICE = $CFNQTY *50;
$CVNPRICE = $CVNQTY* 50;



///total price
$totalamount = $NNPRICE+$CBFPRICE+$AKNPRICE+$CFNPRICE+$CVNPRICE;



// total quantity
$totalqty= $NNSQTY+$CBFNQTY+$AKNQTY+$CFNQTY+$CVNQTY;

//mail
$to = "mowtripleh@hotmail.com";
$subject = "order from" . $name;
$email = $_POST['email'];
$message = "<b><center><font face=\"arial\" size=\"3\" color=\"white\">" . $name . " has ordered the following items:</center>\n
\n
<center><table border=\"1\" bordercolor=\"white\">\n
<tr><td>Necklace:</td><td> Length</td><td> Pattern</td><td> Bead Color</td><td> Bead Size</td><td> Chain Size</td><td>Bead Type</td><td>Quantity</td><td>Subtotal:</td></tr>\n
<tr><td>Necklace of the Night Sky:</td><td>" . $NNSL . "</td><td>" . $NNSP . "</td<td>" . $NNSBC . "</td><td>" . $NNSBS . "</td><td>" . $NNS_size . "</td><td>" . $NNSBT . "</td><td> " . $NNSQTY . " </td><td>\$" . $NNPRICE . "</tr>\n
<tr><td>Chainmaile Beaded FancyNecklace:</td><td>" . $CBFNL . "</td><td>" . $CBFNP . "</td><td>" . $CBFNBC . "</td><td>" . $CBFNBS . "</td><td>" . $CBFN_size . "</td><td>" . $CBFNBT . "</td><td>" . $CBFNQTY . "</td><td>\$" . $CBFPRICE . "</td></tr>\n
<tr><td>Antique Key Necklace:</td><td>" . $AKNL . "</td><td>" . $AKNP . "</td><td>" . $AKNBC . "</td><td>" . $AKNBS . "</td><td>" . $AKN_size . "</td><td>" . $AKNBT . "</td><td>" . $AKNQTY . "</td><td>\$" . $AKNPRICE . "</td></tr>\n
<tr><td>Chainmaile Fancy Necklace:</td><td>" . $CFNL . "</td><td>" . $CFNP . "</td><td>" . $CFNBC . "</td><td>" . $CFNBS . "</td><td>" . $CFN_size . "</td><td>" . $CFNBT . "</td><td>" . $CFNQTY . "</td><td>\$" . $CFNPRICE . "</td></tr>\n
<tr><td>Chainmaile V Necklace:</td><td>" . $CVNL . "</td><td>" . $CVNP . "</td><td>" . $CVNBC . "</td><td>" . $CVNBS . "</td><td>" . $CVN_size . "</td><td>" . $CVNBT . "</td><td>" . $CVNQTY . "</td><td>\$" . $CVNPRICE . "</td></tr>\n
<tr><td colspan=\"9\"><hr></td></tr>
<tr><td>Total:</td><td></td><td></td><td></td><td></td><td></td><td>". $totalqty . "</td><td>\$" . $totalamount . "</td></tr>\n
</font></table></center>";
if (mail($to,$subject,$message,"From: $email\n",$header)) {echo '<font color=\"white\">Your order has been sent to ', $to, ' from ', $email, ' with the subject ', $subject, ' and the following message:<br>', $message, '.</font>';} 
else {echo "Something went wrong. Please send an email directly to admin@tatoos-n-piercings.com";}}
[/syntax]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The content-type must be specified in $header.

Unless you actually have constants set for all your requests into $_POST, you'll have mountains of notices firing. I'm pretty sure you've been told this before but I'll try one more time:

Code: Select all

$_POST[NNSQTY]
should be

Code: Select all

$_POST['NNSQTY']
most often.
darkfreaks
Forum Commoner
Posts: 59
Joined: Sat Sep 09, 2006 3:59 pm

Post by darkfreaks »

hmmm when i put

Code: Select all


[syntax=php]$header= ("content-type: text/html");

mail ( $to, $subject, $message, "From: $email\n",$header)
[/syntax]


it says please contact admin because i told it if it didnt mail to display that message
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Do you have error_reporting turned way down or display_errors off? Run the following in a new file and tell us the results please.

Code: Select all

<?php

$neg = array('off', 0, false, '', null);
$flags = array(
	'Register Globals' => 'register_globals',
	'Short Tags' => 'short_open_tag',
	'Display Errors' => 'display_errors',
	'Magic Quotes GPC' => 'magic_quotes_gpc',
	'Magic Quotes Runtime' => 'magic_quotes_runtime',
	'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
	$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";

$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
	$le .= '   ' . implode('   ', array_slice($gle, $i, $wide)) . $eol;
}

$ec = array(
	'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
	'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
	'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
	'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
	if (($t & $v) == $v)
	{
		$e[] = $n;
		$t ^= $v;
	}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
	$e2 = array();
	foreach ($ec as $n => $v)
	{
		if (!in_array($n, $e) and $n != 'E_ALL')
		{
			$e2[] = $n;
		}
	}
	$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
	$er = $er . ' (' . implode(' | ', $e) . ')';
}

if (!$cli)
{
	echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}

echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
	echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;

if (!$cli)
{
	echo '</pre></body></html>', $eol;
}

?>
mail() expects a maximum of four arguments; you're giving it five.
darkfreaks
Forum Commoner
Posts: 59
Joined: Sat Sep 09, 2006 3:59 pm

Post by darkfreaks »

Results

Code: Select all

PHP Version: 4.4.4
PHP OS: Linux
Error Reporting: 2039 ((E_ALL | E_STRICT) ^ E_STRICT ^ E_NOTICE))
Register Globals: Off
Short Tags: On
Display Errors: On
Magic Quotes GPC: On
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Loaded Extensions:
   zip              xslt             xmlrpc           xml           
   wddx             tokenizer        swf              standard      
   sockets          session          pspell           posix         
   overload         mysql            mhash            mcrypt        
   mbstring         imap             gettext          gd            
   ftp              exif             domxml           curl          
   ctype            calendar         bcmath           zlib          
   pcre             openssl          apache           Zend Optimizer
darkfreaks
Forum Commoner
Posts: 59
Joined: Sat Sep 09, 2006 3:59 pm

Post by darkfreaks »

is there a way i could combine one of the mail arguements ot make it 4?
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

Code: Select all

<?php
//...
$to      = $email;
$subject = 'Test ';
$message = "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html dir="ltr" xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
...
</body>
</html>";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: me@example.com' . "\r\n" .
 'Reply-To: me@example.com' . "\r\n" .
 'X-Mailer: PHP/' . phpversion();

if(!mail($to, $subject, $message, $headers))
{
 echo ":(";
}else{
 echo ":)";
}
//...
?>
Try the above, it should work.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

What about using SwiftMailer?

Your problem would be solved by this tutorial...
darkfreaks
Forum Commoner
Posts: 59
Joined: Sat Sep 09, 2006 3:59 pm

Post by darkfreaks »

something is going horribly wrong..
.

Code: Select all

[syntax=php]$to = "mowtripleh@hotmail.com";
$subject = "order from" . $name;
$email = $_POST['email'];
$headers  = 'MIME-Version: 1.0' . "\r\n"; 
$headers = 'Content-type: text/html; charset=utf-8' . "\r\n"; 
$headers = 'From: $to' . "\r\n" . 
 'Reply-To: $to' . "\r\n" 

if (mail($headers,$subject,$message,$email)) {echo '<font color=\"white\">Your order has been sent to ', $to, ' from ', $email, ' with the subject ', $subject, ' and the following message:<br>', $message, '.</font>';} 
else {echo "Something went wrong. Please send an email directly to admin@tatoos-n-piercings.com";}}
[/syntax]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Wrong order of arguments.
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

nickvd wrote:What about using SwiftMailer?
Try using SwiftMailer or PHPMailer.

If you still want to use mail(), read the manual about mail(): http://php.net/mail.
darkfreaks
Forum Commoner
Posts: 59
Joined: Sat Sep 09, 2006 3:59 pm

Post by darkfreaks »

nah thats fine i still can use the mail function i just need someone to tell me how i would combine one of the other arguements into the header. i cant inject my email into the header because now it doesnt email me. but the other arguements i think can be combined.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Psst, .= not =

;)
Post Reply