Log in

View Full Version : Mailing html with php



captainjustin
01-13-2010, 11:56 PM
I created a page to for ordering supplies and everything seems displays properly when you hit send button the mail is sent just fine, But it doesn't display the php for some reason..... Where I'm trying to echo the quantity in the email it just shows the php code. I don't expect anyone to fix the whole page but, if anyone could get me started in the right direction it would be a huge help.....

Thanks in advance



<? include("accesscontrol.php");


$pday = date('d', mktime(0,0,0,0, date(d)));

$pmonth = date('m', mktime(0,0,0, date(m), date(d)));

$pyear = date('Y', mktime(0,0,0,date(m) ,date(d) , date(Y)));


if(isset($s1))

{

$odoban = $_POST['odoban'];

mail('myemail@gmail.com', 'Supply Requisition',

'<html><body><p><b><i><table align="center" border="0" cellspacing="0" cellpadding="0"><tr><td><table style="table-layout:fixed;border:2px outset #000099" width=535 height=550 border=2 cellspacing=4 cellpadding=0><col width="167"><col width="167"><col width="167"><tr>
<td style="border:1px inset #CCCCCC" width="165" height="21" align="left" valign="top" bgcolor="#CCCCCC"><span class="text"><b><span style="font-size:12px;line-height:19px;">

////////////////I think this is where I'm messing up?//////////////////////////


<input name="odoban" value="<?php echo $odoban;?>" type="text" id="odoban" size="1">&nbsp;Odoban Disinfectant</b></a></span></td>
<td style="border:1px inset #CCCCCC" width="165" height="21" align="left" valign="top" bgcolor="#CCCCCC"><span class="text"> <b><span style="font-size:12px;line-height:19px;"><input name="nav_lt" value="$nav_lt" type="text" id="odoban" size="1">&nbsp;Navigation Light Bulbs<br soft></span></u></b></a></span></td>
<td style="border:1px inset #CCCCCC" width="165" height="21" align="left" valign="top" bgcolor="#CCCCCC"><span class="text"> <b><span style="font-size:12px;line-height:19px;"><input name="brake" value="$brake" type="text" id="brake" size="1">&nbsp;Brake-Kleen Parts Cleaner<br soft></span></u></b></a></span></td>



</table>

</form>

bluewalrus
01-14-2010, 12:42 AM
You have to set the header to accept the html and you cant have variables in single quotes if you want them to display that actual value.

For a more detailed example


<?php
// multiple recipients
$to = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';

// subject
$subject = 'Birthday Reminders for August';

// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>


For more info http://php.net/manual/en/function.mail.php

bluewalrus
01-14-2010, 12:56 AM
To be more specific


<? include("accesscontrol.php");

$pday = date('d', mktime(0,0,0,0, date(d)));

$pmonth = date('m', mktime(0,0,0, date(m), date(d)));

$pyear = date('Y', mktime(0,0,0,date(m) ,date(d) , date(Y)));

if(isset($s1)){

$odoban = $_POST['odoban'];
$to = 'myemail@gmail.com'
// subject
$subject = 'Supply Requisition';

// message
$message = '<html><body><p><b><i><table align="center" border="0" cellspacing="0" cellpadding="0"><tr><td><table style="table-layout:fixed;border:2px outset #000099" width=535 height=550 border=2 cellspacing=4 cellpadding=0><col width="167"><col width="167"><col width="167"><tr><td style="border:1px inset #CCCCCC" width="165" height="21" align="left" valign="top" bgcolor="#CCCCCC"><span class="text"><b><span style="font-size:12px;line-height:19px;"><input name="odoban" value="'. $odoban .'" type="text" id="odoban" size="1">&nbsp;Odoban Disinfectant</b></a></span></td><td style="border:1px inset #CCCCCC" width="165" height="21" align="left" valign="top" bgcolor="#CCCCCC"><span class="text"> <b><span style="font-size:12px;line-height:19px;"><input name="nav_lt" value="'. $nav_lt . '" type="text" id="odoban" size="1">&nbsp;Navigation Light Bulbs<br soft></span></u></b></a></span></td><td style="border:1px inset #CCCCCC" width="165" height="21" align="left" valign="top" bgcolor="#CCCCCC"><span class="text"> <b><span style="font-size:12px;line-height:19px;"><input name="brake" value="'. $brake . '" type="text" id="brake" size="1">&nbsp;Brake-Kleen Parts Cleaner<br soft></span></u></b></a></span></td></table></form></body></html>';

// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Me <me@mydomain.com>' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
}
?>

You dont need the <?php because that's going to be parsed before it's sent. You also needed to close the body and html which i added in and close the if isset which i did not sure if this was a snippet or your whole code.