Jump to content

Email Question


brnevs

Recommended Posts

Greetings everyone!I've got one question about email that maybe you can help with:I am trying to send an email with a big message, and I am in doubt if I can use a mix of html and php, as my tries only seem to fail....here is the code I want to send in my email message:

<table class="page" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><hr/><td><h2 class="tutheader">Os seus dados<?php echo " ", $_SESSION['nom']; ?>:</h2><div class="left_box"><li>Morada: </div><?php echo $_SESSION['mor']. " " .$_SESSION['loc']. " " .$_SESSION['cpos']. " " .$_SESSION['cid']. " " .$_SESSION['pais'];?><div class="left_box"><li>Email: </div><?php echo $_SESSION['mail'];?><div class="left_box"><li>Telefone:</div><?php echo $_SESSION['tel'];?><br><br><table class="page" align="center" width="98%" border="1" cellpadding="0" cellspacing="0"><tr>    <td class="table" width="5%"> </td>  <td class="table" width="25%"><h2 class="right">Categoria</h2></td>  <td class="table" width="20%"><h2 class="right">Marca</h2></td>  <td class="table" width="30%"><h2 class="right">Modelo</h2></td>  <td class="table" width="20%"><h2 class="right">Quan.</h2></td>  <td class="table" width="20%"><h2 class="right">Total</h2></td></tr>   <? 	$li = mysql_num_rows ($rnc);	for ($a=1; $a<=$li; $a++) {	$s = mysql_fetch_assoc($rnc);	$result = db_query("SELECT * FROM produtos WHERE cod='" . mysql_real_escape_string($s['cod']) . "'");	$se = mysql_fetch_assoc($result);	echo '<tr><td class="edit" height="30px" width="30px"><a href="http://127.0.0.1/projecto/del.php?r='.$s['cod'].'"> </td>';	echo '<td width="25%"><h3>'.$se['cat'].'</td>';	echo '<td width="20%"><h3>'.$se['mar'].'</td>';	echo '<td width="30%"><h3>'.$se['mod'].'</td>';	$pt = $se['pvp'] * $s['quan'];	$pf+=$pt;	echo '<td width="30%"><h3>'.$s['quan'].'</td>';	echo '<td width="20%"><h3>'.$pt.'</td></tr>';}echo '<tr><td class="table" width="5%"> </td><td class="table" width="5%"> </td><td class="table" width="5%"> </td><td class="table" width="5%"> </td><td class="table" width="20%"><h2 class="right">Total</h2></td><td class="table" width="20%"><h2 class="right">'.$pf.'</h2></td></tr>';?>  </table>

How can I pass this into my $message variable?Here is the code that will after send the email:

if(isset($_POST['comp'])){$to = $_SESSION['mail'];$subject = "Compra n".$_SESSION['ncon'];		//$message = "Hello! This is a simple email message.";	??$headers = "From: webmaster@infohous.com" . "\r\n" ."Bcc: orders@infohous.com";mail($to,$subject,$message,$headers);echo "Mail Sent.";

Link to comment
Share on other sites

Assign the first code in a variable, or simple save the first code as PHP file and call the URL by file_get_contents function in the other:

$message = file_get_contents('path/to/the php file');

Link to comment
Share on other sites

the thing is that I need to process it in the .php file I'm working it first and show it, only then the user will press a button which will send the e-mail and clean some variables that won't be needed anymore... I'd prefer to work with that code from inside a variable, but I can't assign it to a variable because I have the <?php ?> and it always brakes before the last ?>, wich means that I'm not getting all the code I need.....

Link to comment
Share on other sites

You just need to build your HTML in a variable instead of echoing it. You can echo the variable if you want to output it, or you can use it as the body of the message.

<?php$message = <<<EOT<table class="page" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><hr/><td><h2 class="tutheader">Os seus dados $_SESSION['nom']:</h2><div class="left_box"><li>Morada: </div> $_SESSION['mor'] $_SESSION['loc'] $_SESSION['cpos'] $_SESSION['cid'] $_SESSION['pais']<div class="left_box"><li>Email: </div>echo $_SESSION['mail']<div class="left_box"><li>Telefone:</div>$_SESSION['tel']<br><br><table class="page" align="center" width="98%" border="1" cellpadding="0" cellspacing="0"><tr>    <td class="table" width="5%"> </td>  <td class="table" width="25%"><h2 class="right">Categoria</h2></td>  <td class="table" width="20%"><h2 class="right">Marca</h2></td>  <td class="table" width="30%"><h2 class="right">Modelo</h2></td>  <td class="table" width="20%"><h2 class="right">Quan.</h2></td>  <td class="table" width="20%"><h2 class="right">Total</h2></td></tr>EOT;$li = mysql_num_rows ($rnc);for ($a=1; $a<=$li; $a++) {	$s = mysql_fetch_assoc($rnc);	$result = db_query("SELECT * FROM produtos WHERE cod='" . mysql_real_escape_string($s['cod']) . "'");	$se = mysql_fetch_assoc($result);	$message .= '<tr><td class="edit" height="30px" width="30px"><a href="http://127.0.0.1/projecto/del.php?r='.$s['cod'].'">&nbsp</td>';	$message .= '<td width="25%"><h3>'.$se['cat'].'</td>';	$message .= '<td width="20%"><h3>'.$se['mar'].'</td>';	$message .= '<td width="30%"><h3>'.$se['mod'].'</td>';	$pt = $se['pvp'] * $s['quan'];	$pf+=$pt;	$message .= '<td width="30%"><h3>'.$s['quan'].'</td>';	$message .= '<td width="20%"><h3>'.$pt.'</td></tr>';}$message .= '<tr><td class="table" width="5%"> </td><td class="table" width="5%"> </td><td class="table" width="5%"> </td><td class="table" width="5%"> </td><td class="table" width="20%"><h2 class="right">Total</h2></td><td class="table" width="20%"><h2 class="right">'.$pf.'</h2></td></tr></table>';echo $message;$to = $_SESSION['mail'];$subject = "Compra n".$_SESSION['ncon'];$headers = "From: webmaster@infohous.com" . "\r\n" . "Bcc: orders@infohous.com";mail($to,$subject,$message,$headers);echo "Mail Sent.";?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...