matt.sisto Posted May 6, 2009 Share Posted May 6, 2009 Hi all, I have put together my script for compiling my invoice, which outputs in HTML tables, but I now want to send this HTML page via mail, can it be done? <?php session_start(); if (!isset($_SESSION['username'])) { header("Location: login.php"); exit(); } require "dbconn2.php"; $org_id = $_POST["org_id"]; $month1 = $_POST["month1"]; $day1 = $_POST["day1"]; $year1 = $_POST["year1"]; $month2 = $_POST["month2"]; $day2 = $_POST["day2"]; $year2 = $_POST["year2"]; $invoice_start = $year1."-".$month1."-".$day1." ".$_POST["event_start"]; $invoice_end = $year2."-".$month2."-".$day2." ".$_POST["event_end"]; $sql = "SELECT SUM(fee) FROM calendar_events CROSS JOIN client USING (client_id) WHERE calendar_events.event_start >= '".$invoice_start."' AND calendar_events.event_end <= '".$invoice_end."' AND client.org_id = '".$org_id."'"; $result = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); if($result !=null){ $totalFee = mysql_result($result, 0); } $vat = (int)$totalFee/100*15; $invoiceFee = (int)$vat + (int)$totalFee; $sql = "SELECT title, address_first_line, post_code, first_name, last_name, email_address FROM organisation where org_id = '".$org_id."'"; $result1 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); $sql = "SELECT client_id, first_name, last_name, email_address FROM client where org_id = '".$org_id."'"; $result2 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); $sql = "SELECT event_id, event_start, event_end, service_id, unit, quantity, fee FROM calendar_events CROSS JOIN client USING (client_id) WHERE calendar_events.event_start >= '".$invoice_start."' AND calendar_events.event_end <= '".$invoice_end."' AND client.org_id = '".$org_id."'"; $result3 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); ?> <html> <head> <title>Invoice</title> </head> <body> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th align="center">Logo </th> <th align="center">Address</th> <th align="center">SRC: Striving to achieve excellence</th> <th align="center">Email Address</th> </tr> </table> <legend>Invoice Start: <?php echo "$invoice_start"?> Invoice End: <?php echo "$invoice_end"?> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th bgcolor="#CCCCCC" align="center">Title </th> <th bgcolor="#CCCCCC" align="center">Address</th> <th bgcolor="#CCCCCC" align="center">Post Code</th> <th bgcolor="#CCCCCC" align="center">Admin First Name</th> <th bgcolor="#CCCCCC" align="center">Admin Last Name</th> <th bgcolor="#CCCCCC" align="center">Email Address</th> </tr> <?php while ($row = mysql_fetch_array($result1)) {?> <tr> <td align="center"><?=$row['title']?></td> <td align="center"><?=$row['address_first_line']?></td> <td align="center"><?=$row['post_code']?></td> <td align="center"><?=$row['first_name']?></td> <td align="center"><?=$row['last_name']?></td> <td align="center"><?=$row['email_address']?></td> </tr> <?php } ?> </table> <br /> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th bgcolor="#CCCCCC" align="center"> Client ID </th> <th bgcolor="#CCCCCC" align="center">First Name</th> <th bgcolor="#CCCCCC" align="center">Last Name</th> <th bgcolor="#CCCCCC" align="center">Email Address</th> </tr> <?php while ($row = mysql_fetch_array($result2)) {?> <tr> <td align="center"><?=$row['client_id']?></td> <td align="center"><?=$row['first_name']?></td> <td align="center"><?=$row['last_name']?></td> <td align="center"><?=$row['email_address']?></td ></tr> <?php } ?> </table> <br /> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th bgcolor="#CCCCCC" align="center">Event ID</th> <th bgcolor="#CCCCCC" align="center">Client ID</th> <th bgcolor="#CCCCCC" align="center">Service ID</th> <th bgcolor="#CCCCCC" align="center">Unit</th> <th bgcolor="#CCCCCC" align="center">Quantity</th> <th bgcolor="#CCCCCC" align="center">Start Date</th> <th bgcolor="#CCCCCC" align="center">End Date</th> <th bgcolor="#CCCCCC" align="center">Fee [£]</th> <th bgcolor="#CCCCCC" align="center">Remove</th> </tr> <?php while ($row = mysql_fetch_array($result3)) {?> <tr> <td align="center"><?=$row['event_id']?></td> <td align="center"><?=$row['client_id']?></td> <td align="center"><?=$row['service_id']?></td> <td align="center"><?=$row['unit']?></td> <td align="center"><?=$row['quantity']?></td> <td align="center"><?=$row['event_start']?></td> <td align="center"><?=$row['event_end']?></td> <td align="center"><?=$row['fee']?></td> <td align="center"><a href="deleteevent.php?event_id=<?=$row['event_id']?>">[-]</a></td> </tr> <?php } ?> </table> <br /> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th bgcolor="#CCCCCC" align="center">Sub Total [£]</th> <th bgcolor="#CCCCCC" align="center">VAT [£]</th> <th bgcolor="#CCCCCC" align="center">Total [£]</th> </tr> <tr> <td align="center"><?php echo "$totalFee"?></td> <td align="center"><?php echo "$vat"?></td> <td align="center"><?php echo "$invoiceFee"?></td> </tr> </table> </legend> </body> </html> Appreciate any help and advice. Thanks and regs. Quote Link to comment https://forums.phpfreaks.com/topic/157138-solved-sending-my-html-page-using-php-mail-function/ Share on other sites More sharing options...
matt.sisto Posted May 6, 2009 Author Share Posted May 6, 2009 I was thinking something like this: <?php session_start(); if (!isset($_SESSION['username'])) { header("Location: login.php"); exit(); } require "dbconn2.php"; $org_id = $_POST["org_id"]; $month1 = $_POST["month1"]; $day1 = $_POST["day1"]; $year1 = $_POST["year1"]; $month2 = $_POST["month2"]; $day2 = $_POST["day2"]; $year2 = $_POST["year2"]; $invoice_start = $year1."-".$month1."-".$day1." ".$_POST["event_start"]; $invoice_end = $year2."-".$month2."-".$day2." ".$_POST["event_end"]; $sql = "SELECT SUM(fee) FROM calendar_events CROSS JOIN client USING (client_id) WHERE calendar_events.event_start >= '".$invoice_start."' AND calendar_events.event_end <= '".$invoice_end."' AND client.org_id = '".$org_id."'"; $result = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); if($result !=null){ $totalFee = mysql_result($result, 0); } $vat = (int)$totalFee/100*15; $invoiceFee = (int)$vat + (int)$totalFee; $sql = "SELECT email_address FROM organisation where org_id = '".$org_id."'"; $result1 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); if($result !=null){ $to = mysql_result($result, 0); } $sql = "SELECT title, address_first_line, post_code, first_name, last_name, email_address FROM organisation where org_id = '".$org_id."'"; $result1 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); $sql = "SELECT client_id, first_name, last_name, email_address FROM client where org_id = '".$org_id."'"; $result2 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); $sql = "SELECT event_id, event_start, event_end, service_id, unit, quantity, fee FROM calendar_events CROSS JOIN client USING (client_id) WHERE calendar_events.event_start >= '".$invoice_start."' AND calendar_events.event_end <= '".$invoice_end."' AND client.org_id = '".$org_id."'"; $result3 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); $subject ='Invoice'; $headers = 'From: info <admin@salmonsreach.org>'; $message = ' <html> <head> <title>Invoice</title> </head> <body> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th align="center">Logo </th> <th align="center">Address</th> <th align="center">SRC: Striving to achieve excellence</th> <th align="center">Email Address</th> </tr> </table> <legend>Invoice Start: <?php echo "$invoice_start"?> Invoice End: <?php echo "$invoice_end"?> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th bgcolor="#CCCCCC" align="center">Title </th> <th bgcolor="#CCCCCC" align="center">Address</th> <th bgcolor="#CCCCCC" align="center">Post Code</th> <th bgcolor="#CCCCCC" align="center">Admin First Name</th> <th bgcolor="#CCCCCC" align="center">Admin Last Name</th> <th bgcolor="#CCCCCC" align="center">Email Address</th> </tr> <?php while ($row = mysql_fetch_array($result1)) {?> <tr> <td align="center"><?=$row['title']?></td> <td align="center"><?=$row['address_first_line']?></td> <td align="center"><?=$row['post_code']?></td> <td align="center"><?=$row['first_name']?></td> <td align="center"><?=$row['last_name']?></td> <td align="center"><?=$row['email_address']?></td> </tr> <?php } ?> </table> <br /> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th bgcolor="#CCCCCC" align="center"> Client ID </th> <th bgcolor="#CCCCCC" align="center">First Name</th> <th bgcolor="#CCCCCC" align="center">Last Name</th> <th bgcolor="#CCCCCC" align="center">Email Address</th> </tr> <?php while ($row = mysql_fetch_array($result2)) {?> <tr> <td align="center"><?=$row['client_id']?></td> <td align="center"><?=$row['first_name']?></td> <td align="center"><?=$row['last_name']?></td> <td align="center"><?=$row['email_address']?></td ></tr> <?php } ?> </table> <br /> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th bgcolor="#CCCCCC" align="center">Event ID</th> <th bgcolor="#CCCCCC" align="center">Client ID</th> <th bgcolor="#CCCCCC" align="center">Service ID</th> <th bgcolor="#CCCCCC" align="center">Unit</th> <th bgcolor="#CCCCCC" align="center">Quantity</th> <th bgcolor="#CCCCCC" align="center">Start Date</th> <th bgcolor="#CCCCCC" align="center">End Date</th> <th bgcolor="#CCCCCC" align="center">Fee [£]</th> <th bgcolor="#CCCCCC" align="center">Remove</th> </tr> <?php while ($row = mysql_fetch_array($result3)) {?> <tr> <td align="center"><?=$row['event_id']?></td> <td align="center"><?=$row['client_id']?></td> <td align="center"><?=$row['service_id']?></td> <td align="center"><?=$row['unit']?></td> <td align="center"><?=$row['quantity']?></td> <td align="center"><?=$row['event_start']?></td> <td align="center"><?=$row['event_end']?></td> <td align="center"><?=$row['fee']?></td> <td align="center"><a href="deleteevent.php?event_id=<?=$row['event_id']?>">[-]</a></td> </tr> <?php } ?> </table> <br /> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th bgcolor="#CCCCCC" align="center">Sub Total [£]</th> <th bgcolor="#CCCCCC" align="center">VAT [£]</th> <th bgcolor="#CCCCCC" align="center">Total [£]</th> </tr> <tr> <td align="center"><?php echo "$totalFee"?></td> <td align="center"><?php echo "$vat"?></td> <td align="center"><?php echo "$invoiceFee"?></td> </tr> </table> </legend> </body> </html> '; mail($to, $subject, $message, $headers); ?> Question is will it work? ??? Quote Link to comment https://forums.phpfreaks.com/topic/157138-solved-sending-my-html-page-using-php-mail-function/#findComment-827952 Share on other sites More sharing options...
matt.sisto Posted May 6, 2009 Author Share Posted May 6, 2009 Well that didn't work. ??? Quote Link to comment https://forums.phpfreaks.com/topic/157138-solved-sending-my-html-page-using-php-mail-function/#findComment-827964 Share on other sites More sharing options...
Brian W Posted May 6, 2009 Share Posted May 6, 2009 Something like this <?php $to = "johndoe@thesite.com"; $subject = "Hello"; $body = "<span style=\"font-size:12pt\">HI!</span>"; $headers = "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=utf-8\n"; $headers .= "From: Your Pal <yourname@yoursite.com>\n"; if(!mail($to, $subject, $body, $headers)){ die("Error sending message"); } The header Content-type specifies to use html. Some tags aren't supported, but they are far and few so no worries there. No JS and I don't believe CSS is supported usually. Quote Link to comment https://forums.phpfreaks.com/topic/157138-solved-sending-my-html-page-using-php-mail-function/#findComment-828060 Share on other sites More sharing options...
matt.sisto Posted May 7, 2009 Author Share Posted May 7, 2009 Tried what you suggested but it doesn't seem to be working, don't know what I'm doing wrong. ??? <?php session_start(); if (!isset($_SESSION['username'])) { header("Location: login.php"); exit(); } require "dbconn2.php"; $org_id = $_POST["org_id"]; $month1 = $_POST["month1"]; $day1 = $_POST["day1"]; $year1 = $_POST["year1"]; $month2 = $_POST["month2"]; $day2 = $_POST["day2"]; $year2 = $_POST["year2"]; $invoice_start = $year1."-".$month1."-".$day1." ".$_POST["event_start"]; $invoice_end = $year2."-".$month2."-".$day2." ".$_POST["event_end"]; $sql = "SELECT SUM(fee) FROM calendar_events CROSS JOIN client USING (client_id) WHERE calendar_events.event_start >= '".$invoice_start."' AND calendar_events.event_end <= '".$invoice_end."' AND client.org_id = '".$org_id."'"; $result = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); if($result !=null){ $totalFee = mysql_result($result, 0); } $vat = (int)$totalFee/100*15; $invoiceFee = (int)$vat + (int)$totalFee; $sql = "SELECT email_address FROM organisation where org_id = '".$org_id."'"; $result1 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); if($result !=null){ $to = mysql_result($result, 0); } $sql = "SELECT title, address_first_line, post_code, first_name, last_name, email_address FROM organisation where org_id = '".$org_id."'"; $result1 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); $sql = "SELECT client_id, first_name, last_name, email_address FROM client where org_id = '".$org_id."'"; $result2 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); $sql = "SELECT event_id, event_start, event_end, service_id, unit, quantity, fee FROM calendar_events CROSS JOIN client USING (client_id) WHERE calendar_events.event_start >= '".$invoice_start."' AND calendar_events.event_end <= '".$invoice_end."' AND client.org_id = '".$org_id."'"; $result3 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); $headers = "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=utf-8\n"; $headers = "From: Admin <admin@salmonsreach.org>"; $subject ="SRC: Invoice"; $body = " <html> <head> <title>Invoice</title> </head> <body> <table id=\"table\" cellpadding=\"1px\" cellspacing=\"1px\" bordercolordark=\"#333\"> <tr> <th align=\"center\">Logo </th> <th align=\"center\">Address</th> <th align=\"center\">SRC: Striving to achieve excellence</th> <th align=\"center\">Email Address</th> </tr> </table> <h1>Organisation:<?php echo\"$title\"?>Invoice Start:<?php echo\"$invoice_start\"?> Invoice End:<?php echo\"$invoice_end\"?></h1>//For some reason a couple of the slashes are not being displayed? <table id=\"table\" cellpadding=\"1px\" cellspacing=\"1px\" bordercolordark=\"#333\"> <tr> <th align=\"center\">Logo </th> <th align=\"center\">Address</th> <th align=\"center\">SRC: Striving to achieve excellence</th> <th align=\"center\">Email Address</th> </tr> </table> <br /> <table id=\"table\" cellpadding=\"1px\" cellspacing=\"1px\" bordercolordark=\"#333\"> <tr> <th bgcolor=\"#CCCCCC\" align=\"center\">Title </th> <th bgcolor=\"#CCCCCC\" align=\"center\">Address</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Post Code</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Admin First Name</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Admin Last Name</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Email Address</th> </tr> <?php while ($row = mysql_fetch_array($result1)) {?> <tr> <td align=\"center\"><?=$row['title']?></td> <td align=\"center\"><?=$row['address_first_line']?></td> <td align=\"center\"><?=$row['post_code']?></td> <td align=\"center\"><?=$row['first_name']?></td> <td align=\"center\"><?=$row['last_name']?></td> <td align=\"center\"><?=$row['email_address']?></td> </tr> <?php } ?> </table> <br /> <table id=\"table\" cellpadding=\"1px\" cellspacing=\"1px\" bordercolordark=\"#333\"> <tr> <th bgcolor=\"#CCCCCC\" align=\"center\"> Client ID </th> <th bgcolor=\"#CCCCCC\" align=\"center\">First Name</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Last Name</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Email Address</th> </tr> <?php while ($row = mysql_fetch_array($result2)) {?> <tr> <td align=\"center\"><?=$row['client_id']?></td> <td align=\"center\"><?=$row['first_name']?></td> <td align=\"center\"><?=$row['last_name']?></td> <td align=\"center\"><?=$row['email_address']?></td ></tr> <?php } ?> </table> <br /> <table id=\"table\" cellpadding=\"1px\" cellspacing=\"1px\" bordercolordark=\"#333\"> <tr> <th bgcolor=\"#CCCCCC\" align=\"center\">Event ID</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Client ID</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Service ID</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Unit</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Quantity</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Start Date</th> <th bgcolor=\"#CCCCCC\" align=\"center\">End Date</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Fee [£]</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Remove</th> </tr> <?php while ($row = mysql_fetch_array($result3)) {?> <tr> <td align=\"center\"><?=$row['event_id']?></td> <td align=\"center\"><?=$row['client_id']?></td> <td align=\"center\"><?=$row['service_id']?></td> <td align=\"center\"><?=$row['unit']?></td> <td align=\"center\"><?=$row['quantity']?></td> <td align=\"center\"><?=$row['event_start']?></td> <td align=\"center\"><?=$row['event_end']?></td> <td align=\"center\"><?=$row['fee']?></td> <td align=\"center\"><a href=\"deleteevent.php?event_id=<?=$row['event_id']?>\">[-]</a></td> </tr> <?php } ?> </table> <br /> <table id=\"table\" cellpadding=\"1px\" cellspacing=\"1px\" bordercolordark=\"#333\"> <tr> <th bgcolor=\"#CCCCCC\" align=\"center\">Sub Total [£]</th> <th bgcolor=\"#CCCCCC\" align=\"center\">VAT [£]</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Total [£]</th> </tr> <tr> <td align=\"center\"><?php echo \"$totalFee\"?></td> <td align=\"center\"><?php echo \"$vat\"?></td> <td align=\"center\"><?php echo \"$invoiceFee\"?></td> </tr> </table> </legend> </body> </html> "; if(!mail($to, $subject, $body, $headers)){ die("Error sending message"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/157138-solved-sending-my-html-page-using-php-mail-function/#findComment-828284 Share on other sites More sharing options...
premiso Posted May 7, 2009 Share Posted May 7, 2009 $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=utf-8\r\n"; $headers .= "From: Admin <admin@salmonsreach.org>"; You were missing the .= on the 3rd header statement. Also I find that \r\n is better for sending header information. Why it was not working as the 3rd header statement was wiping the previous, so it was not sending the right mime-version or content-type. Quote Link to comment https://forums.phpfreaks.com/topic/157138-solved-sending-my-html-page-using-php-mail-function/#findComment-828549 Share on other sites More sharing options...
matt.sisto Posted May 7, 2009 Author Share Posted May 7, 2009 <?php session_start(); if (!isset($_SESSION['username'])) { header("Location: login.php"); exit(); } require "dbconn2.php"; $org_id = $_POST["org_id"]; $month1 = $_POST["month1"]; $day1 = $_POST["day1"]; $year1 = $_POST["year1"]; $month2 = $_POST["month2"]; $day2 = $_POST["day2"]; $year2 = $_POST["year2"]; $invoice_start = $year1."-".$month1."-".$day1." ".$_POST["event_start"]; $invoice_end = $year2."-".$month2."-".$day2." ".$_POST["event_end"]; $sql = "SELECT SUM(fee) FROM calendar_events CROSS JOIN client USING (client_id) WHERE calendar_events.event_start >= '".$invoice_start."' AND calendar_events.event_end <= '".$invoice_end."' AND client.org_id = '".$org_id."'"; $result = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); if($result !=null){ $totalFee = mysql_result($result, 0); } $vat = (int)$totalFee/100*15; $invoiceFee = (int)$vat + (int)$totalFee; $sql = "SELECT email_address FROM organisation where org_id = '".$org_id."'"; $result1 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); if($result1 !=null){ $to = mysql_result($result1, 0); } $sql = "SELECT title, address_first_line, post_code, first_name, last_name, email_address FROM organisation where org_id = '".$org_id."'"; $result1 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); $sql = "SELECT client_id, first_name, last_name, email_address FROM client where org_id = '".$org_id."'"; $result2 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); $sql = "SELECT event_id, event_start, event_end, service_id, unit, quantity, fee FROM calendar_events CROSS JOIN client USING (client_id) WHERE calendar_events.event_start >= '".$invoice_start."' AND calendar_events.event_end <= '".$invoice_end."' AND client.org_id = '".$org_id."'"; $result3 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); $headers ="MIME-Version: 1.0\r\n"; $headers .="Content-type: text/html; charset=utf-8\r\n"; $headers .="From: Admin <admin@salmonsreach.org>"; $subject ="SRC: Invoice"; $body =" <html> <head> <title>Invoice</title> </head> <body> <table id=\"table\" cellpadding=\"1px\" cellspacing=\"1px\" bordercolordark=\"#333\"> <tr> <th align=\"center\">Logo </th> <th align=\"center\">Address</th> <th align=\"center\">SRC: Striving to achieve excellence</th> <th align=\"center\">Email Address</th> </tr> </table> <h1>Organisation: <?php echo \"$title\"?> Invoice Start: <?php echo \"$invoice_start\"?> Invoice End: <?php echo \"$invoice_end\"?></h1> <table id=\"table\" cellpadding=\"1px\" cellspacing=\"1px\" bordercolordark=\"#333\"> <tr> <th align=\"center\">Logo </th> <th align=\"center\">Address</th> <th align=\"center\">SRC: Striving to achieve excellence</th> <th align=\"center\">Email Address</th> </tr> </table> <br /> <table id=\"table\" cellpadding=\"1px\" cellspacing=\"1px\" bordercolordark=\"#333\"> <tr> <th bgcolor=\"#CCCCCC\" align=\"center\">Title </th> <th bgcolor=\"#CCCCCC\" align=\"center\">Address</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Post Code</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Admin First Name</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Admin Last Name</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Email Address</th> </tr> <?php while ($row = mysql_fetch_array($result1)) {?> <tr> <td align=\"center\"><?=$row['title']?></td> <td align=\"center\"><?=$row['address_first_line']?></td> <td align=\"center\"><?=$row['post_code']?></td> <td align=\"center\"><?=$row['first_name']?></td> <td align=\"center\"><?=$row['last_name']?></td> <td align=\"center\"><?=$row['email_address']?></td> </tr> <?php } ?> </table> <br /> <table id=\"table\" cellpadding=\"1px\" cellspacing=\"1px\" bordercolordark=\"#333\"> <tr> <th bgcolor=\"#CCCCCC\" align=\"center\"> Client ID </th> <th bgcolor=\"#CCCCCC\" align=\"center\">First Name</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Last Name</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Email Address</th> </tr> <?php while ($row = mysql_fetch_array($result2)) {?> <tr> <td align=\"center\"><?=$row['client_id']?></td> <td align=\"center\"><?=$row['first_name']?></td> <td align=\"center\"><?=$row['last_name']?></td> <td align=\"center\"><?=$row['email_address']?></td ></tr> <?php } ?> </table> <br /> <table id=\"table\" cellpadding=\"1px\" cellspacing=\"1px\" bordercolordark=\"#333\"> <tr> <th bgcolor=\"#CCCCCC\" align=\"center\">Event ID</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Client ID</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Service ID</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Unit</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Quantity</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Start Date</th> <th bgcolor=\"#CCCCCC\" align=\"center\">End Date</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Fee [£]</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Remove</th> </tr> <?php while ($row = mysql_fetch_array($result3)) {?> <tr> <td align=\"center\"><?=$row['event_id']?></td> <td align=\"center\"><?=$row['client_id']?></td> <td align=\"center\"><?=$row['service_id']?></td> <td align=\"center\"><?=$row['unit']?></td> <td align=\"center\"><?=$row['quantity']?></td> <td align=\"center\"><?=$row['event_start']?></td> <td align=\"center\"><?=$row['event_end']?></td> <td align=\"center\"><?=$row['fee']?></td> <td align=\"center\"><a href=\"deleteevent.php?event_id=<?=$row['event_id']?>\">[-]</a></td> </tr> <?php } ?> </table> <br /> <table id=\"table\" cellpadding=\"1px\" cellspacing=\"1px\" bordercolordark=\"#333\"> <tr> <th bgcolor=\"#CCCCCC\" align=\"center\">Sub Total [£]</th> <th bgcolor=\"#CCCCCC\" align=\"center\">VAT [£]</th> <th bgcolor=\"#CCCCCC\" align=\"center\">Total [£]</th> </tr> <tr> <td align=\"center\"><?php echo \"$totalFee\"?></td> <td align=\"center\"><?php echo \"$vat\"?></td> <td align=\"center\"><?php echo \"$invoiceFee\"?></td> </tr> </table> </legend> </body> </html> "; if(!mail($to, $subject, $body, $headers)){ die("Error sending message"); } ?> Tried this but it just displays a blank screen, do you think it has an issue with the php within the html? Quote Link to comment https://forums.phpfreaks.com/topic/157138-solved-sending-my-html-page-using-php-mail-function/#findComment-828650 Share on other sites More sharing options...
matt.sisto Posted May 7, 2009 Author Share Posted May 7, 2009 <?php while ($row = mysql_fetch_array($result3)) {?> I was thinking it might have problems with these bits? Quote Link to comment https://forums.phpfreaks.com/topic/157138-solved-sending-my-html-page-using-php-mail-function/#findComment-828691 Share on other sites More sharing options...
premiso Posted May 7, 2009 Share Posted May 7, 2009 Your code is honestly a mess. You have the whole HTML in the body, however you go in and out of PHP inside of the string variable. This is not kosher, look at the code you posted on reply #6, you will see where the highlighting goes haywire and yea. I would suggest using ob_start and remove the string definition of the $body. You will have to unescape all the " quotes but it will make it work for you. $subject ="SRC: Invoice"; ob_start(); ?> <!-- your html/php code here --> <?php $body = ob_get_contents(); ob_end_clean(); if(!mail($to, $subject, $body, $headers)){ die("Error sending message"); } ?> You should also look up into variable definitions and proper syntax as well. As it is just a massive mess and clear that you do not fully understand how it should work. Quote Link to comment https://forums.phpfreaks.com/topic/157138-solved-sending-my-html-page-using-php-mail-function/#findComment-828697 Share on other sites More sharing options...
matt.sisto Posted May 7, 2009 Author Share Posted May 7, 2009 I know my code is a mess, but I am still learning. At the moment its trial and error and I have only been learning since christmas so I know I've got alot to learn, but appreciate all the help. I have the hscript working without the mail function. <?php session_start(); if (!isset($_SESSION['username'])) { header("Location: login.php"); exit(); } require "dbconn2.php"; $org_id = $_POST["org_id"]; $month1 = $_POST["month1"]; $day1 = $_POST["day1"]; $year1 = $_POST["year1"]; $month2 = $_POST["month2"]; $day2 = $_POST["day2"]; $year2 = $_POST["year2"]; if( $org_id = 'nil'){ $url = "Location: createInvoice.php?error1=true";//ERROR 1 header($url); exit(); } if( $month1 = 'nil'){ $url = "Location: createInvoice.php?error1=true";//ERROR 1 header($url); exit(); } if( $day1 = 'nil'){ $url = "Location: createInvoice.php?error1=true";//ERROR 1 header($url); exit(); } if( $year1 = 'nil'){ $url = "Location: createInvoice.php?error1=true";//ERROR 1 header($url); exit(); } if( $month2 = 'nil'){ $url = "Location: createInvoice.php?error1=true";//ERROR 1 header($url); exit(); } if( $day2 = 'nil'){ $url = "Location: createInvoice.php?error1=true";//ERROR 1 header($url); exit(); } if( $year2 = 'nil'){ $url = "Location: createInvoice.php?error1=true";//ERROR 1 header($url); exit(); } $invoice_start = $year1."-".$month1."-".$day1." ".$_POST["event_start"]; $invoice_end = $year2."-".$month2."-".$day2." ".$_POST["event_end"]; $sql = "SELECT SUM(fee) FROM calendar_events CROSS JOIN client USING (client_id) WHERE calendar_events.event_start >= '".$invoice_start."' AND calendar_events.event_end <= '".$invoice_end."' AND client.org_id = '".$org_id."'"; $result = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); if($result !=null){ $totalFee = mysql_result($result, 0); } $vat = (int)$totalFee/100*15; $invoiceFee = (int)$vat + (int)$totalFee; $sql = "SELECT title, address_first_line, post_code, first_name, last_name, email_address FROM organisation where org_id = '".$org_id."'"; $result1 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); $sql = "SELECT client_id, first_name, last_name, email_address FROM client where org_id = '".$org_id."'"; $result2 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); $sql = "SELECT event_id, event_start, event_end, service_id, unit, quantity, fee FROM calendar_events CROSS JOIN client USING (client_id) WHERE calendar_events.event_start >= '".$invoice_start."' AND calendar_events.event_end <= '".$invoice_end."' AND client.org_id = '".$org_id."'"; $result3 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); $sql = "SELECT title FROM organisation where org_id = '".$org_id."'"; $result4 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); if($result4 !=null){ $title = mysql_result($result4, 0); } ?> <html> <head> <title>Invoice</title> </head> <body> <h1>Organisation: <?php echo "$title"?> Invoice Start: <?php echo "$invoice_start"?> Invoice End: <?php echo "$invoice_end"?></h1> <div id="mid"> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th align="center">Logo </th> <th align="center">Address</th> <th align="center">SRC: Striving to achieve excellence</th> <th align="center">Email Address</th> </tr> </table> <br /> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th bgcolor="#CCCCCC" align="center">Title </th> <th bgcolor="#CCCCCC" align="center">Address</th> <th bgcolor="#CCCCCC" align="center">Post Code</th> <th bgcolor="#CCCCCC" align="center">Admin First Name</th> <th bgcolor="#CCCCCC" align="center">Admin Last Name</th> <th bgcolor="#CCCCCC" align="center">Email Address</th> </tr> <?php while ($row = mysql_fetch_array($result1)) {?> <tr> <td align="center"><?=$row['title']?></td> <td align="center"><?=$row['address_first_line']?></td> <td align="center"><?=$row['post_code']?></td> <td align="center"><?=$row['first_name']?></td> <td align="center"><?=$row['last_name']?></td> <td align="center"><?=$row['email_address']?></td> </tr> <?php } ?> </table> <br /> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th bgcolor="#CCCCCC" align="center"> Client ID </th> <th bgcolor="#CCCCCC" align="center">First Name</th> <th bgcolor="#CCCCCC" align="center">Last Name</th> <th bgcolor="#CCCCCC" align="center">Email Address</th> </tr> <?php while ($row = mysql_fetch_array($result2)) {?> <tr> <td align="center"><?=$row['client_id']?></td> <td align="center"><?=$row['first_name']?></td> <td align="center"><?=$row['last_name']?></td> <td align="center"><?=$row['email_address']?></td ></tr> <?php } ?> </table> <br /> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th bgcolor="#CCCCCC" align="center">Event ID</th> <th bgcolor="#CCCCCC" align="center">Client ID</th> <th bgcolor="#CCCCCC" align="center">Service ID</th> <th bgcolor="#CCCCCC" align="center">Unit</th> <th bgcolor="#CCCCCC" align="center">Quantity</th> <th bgcolor="#CCCCCC" align="center">Start Date</th> <th bgcolor="#CCCCCC" align="center">End Date</th> <th bgcolor="#CCCCCC" align="center">Fee [£]</th> <th bgcolor="#CCCCCC" align="center">Remove</th> </tr> <?php while ($row = mysql_fetch_array($result3)) {?> <tr> <td align="center"><?=$row['event_id']?></td> <td align="center"><?=$row['client_id']?></td> <td align="center"><?=$row['service_id']?></td> <td align="center"><?=$row['unit']?></td> <td align="center"><?=$row['quantity']?></td> <td align="center"><?=$row['event_start']?></td> <td align="center"><?=$row['event_end']?></td> <td align="center"><?=$row['fee']?></td> <td align="center"><a href="deleteevent.php?event_id=<?=$row['event_id']?>">[-]</a></td> </tr> <?php } ?> </table> <br /> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th bgcolor="#CCCCCC" align="center">Sub Total [£]</th> <th bgcolor="#CCCCCC" align="center">VAT [£]</th> <th bgcolor="#CCCCCC" align="center">Total [£]</th> </tr> <tr> <td align="center"><?php echo "$totalFee"?></td> <td align="center"><?php echo "$vat"?></td> <td align="center"><?php echo "$invoiceFee"?></td> </tr> </table> </div> </body> </html> But it just outputs the queries in a HTML page, and I would like to be able to send it, hence me trying to squeeze it all into the mail function, but clearly I failed. :'( Quote Link to comment https://forums.phpfreaks.com/topic/157138-solved-sending-my-html-page-using-php-mail-function/#findComment-828707 Share on other sites More sharing options...
matt.sisto Posted May 7, 2009 Author Share Posted May 7, 2009 This now works, thanks everyone for all the help. Quote Link to comment https://forums.phpfreaks.com/topic/157138-solved-sending-my-html-page-using-php-mail-function/#findComment-828991 Share on other sites More sharing options...
premiso Posted May 7, 2009 Share Posted May 7, 2009 Glad you were able to figure it out. If it is not too much of a hassle mind posting what you ended up with that worked, in case it may be of further assistance to another user? Quote Link to comment https://forums.phpfreaks.com/topic/157138-solved-sending-my-html-page-using-php-mail-function/#findComment-828994 Share on other sites More sharing options...
matt.sisto Posted May 7, 2009 Author Share Posted May 7, 2009 Thanks again. <?php session_start(); if (!isset($_SESSION['username'])) { header("Location: login.php"); exit(); } require "dbconn2.php"; $org_id = $_POST["org_id"]; $month1 = $_POST["month1"]; $day1 = $_POST["day1"]; $year1 = $_POST["year1"]; $month2 = $_POST["month2"]; $day2 = $_POST["day2"]; $year2 = $_POST["year2"]; if( $org_id == 'nil'){ $url = "Location: createInvoice.php?error1=true";//ERROR 1 header($url); exit(); } if( $month1 == 'nil'){ $url = "Location: createInvoice.php?error1=true";//ERROR 1 header($url); exit(); } if( $day1 == 'nil'){ $url = "Location: createInvoice.php?error1=true";//ERROR 1 header($url); exit(); } if( $year1 == 'nil'){ $url = "Location: createInvoice.php?error1=true";//ERROR 1 header($url); exit(); } if( $month2 == 'nil'){ $url = "Location: createInvoice.php?error1=true";//ERROR 1 header($url); exit(); } if( $day2 == 'nil'){ $url = "Location: createInvoice.php?error1=true";//ERROR 1 header($url); exit(); } if( $year2 == 'nil'){ $url = "Location: createInvoice.php?error1=true";//ERROR 1 header($url); exit(); } $invoice_start = $year1."-".$month1."-".$day1." ".$_POST["event_start"]; $invoice_end = $year2."-".$month2."-".$day2." ".$_POST["event_end"]; $sql = "SELECT SUM(fee) FROM calendar_events CROSS JOIN client USING (client_id) WHERE calendar_events.event_start >= '".$invoice_start."' AND calendar_events.event_end <= '".$invoice_end."' AND client.org_id = '".$org_id."'"; $result = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); if($result !=null){ $totalFee = mysql_result($result, 0); } $vat = (int)$totalFee/100*15; $invoiceFee = (int)$vat + (int)$totalFee; $sql = "SELECT title, address_first_line, post_code, first_name, last_name, email_address FROM organisation where org_id = '".$org_id."'"; $result1 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); $sql = "SELECT client_id, first_name, last_name, email_address FROM client where org_id = '".$org_id."'"; $result2 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); $sql = "SELECT event_id, event_start, event_end, service_id, unit, quantity, fee FROM calendar_events CROSS JOIN client USING (client_id) WHERE calendar_events.event_start >= '".$invoice_start."' AND calendar_events.event_end <= '".$invoice_end."' AND client.org_id = '".$org_id."'"; $result3 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); $sql = "SELECT title FROM organisation where org_id = '".$org_id."'"; $result4 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); if($result4 !=null){ $title = mysql_result($result4, 0); } $sql = "SELECT email_address FROM organisation where org_id = '".$org_id."'"; $result5 = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); if($result5 !=null){ $to = mysql_result($result5, 0); } $headers .="Content-type: text/html; charset=utf-8\r\n"; $headers .="From: Admin <admin@salmonsreach.org>"; $subject ="SRC: Invoice"; ob_start(); ?> <html> <head> <title>Invoice</title> </head> <body> <h1>Organisation: <?php echo "$title"?> Invoice Start: <?php echo "$invoice_start"?> Invoice End: <?php echo "$invoice_end"?></h1> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th align="center">Logo </th> <th align="center">Address</th> <th align="center">SRC: Striving to achieve excellence</th> <th align="center">Email Address</th> </tr> </table> <br /> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th bgcolor="#CCCCCC" align="center">Title </th> <th bgcolor="#CCCCCC" align="center">Address</th> <th bgcolor="#CCCCCC" align="center">Post Code</th> <th bgcolor="#CCCCCC" align="center">Admin First Name</th> <th bgcolor="#CCCCCC" align="center">Admin Last Name</th> <th bgcolor="#CCCCCC" align="center">Email Address</th> </tr> <?php while ($row = mysql_fetch_array($result1)) {?> <tr> <td align="center"><?=$row['title']?></td> <td align="center"><?=$row['address_first_line']?></td> <td align="center"><?=$row['post_code']?></td> <td align="center"><?=$row['first_name']?></td> <td align="center"><?=$row['last_name']?></td> <td align="center"><?=$row['email_address']?></td> </tr> <?php } ?> </table> <br /> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th bgcolor="#CCCCCC" align="center"> Client ID </th> <th bgcolor="#CCCCCC" align="center">First Name</th> <th bgcolor="#CCCCCC" align="center">Last Name</th> <th bgcolor="#CCCCCC" align="center">Email Address</th> </tr> <?php while ($row = mysql_fetch_array($result2)) {?> <tr> <td align="center"><?=$row['client_id']?></td> <td align="center"><?=$row['first_name']?></td> <td align="center"><?=$row['last_name']?></td> <td align="center"><?=$row['email_address']?></td ></tr> <?php } ?> </table> <br /> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th bgcolor="#CCCCCC" align="center">Event ID</th> <th bgcolor="#CCCCCC" align="center">Client ID</th> <th bgcolor="#CCCCCC" align="center">Service ID</th> <th bgcolor="#CCCCCC" align="center">Unit</th> <th bgcolor="#CCCCCC" align="center">Quantity</th> <th bgcolor="#CCCCCC" align="center">Start Date</th> <th bgcolor="#CCCCCC" align="center">End Date</th> <th bgcolor="#CCCCCC" align="center">Fee [£]</th> </tr> <?php while ($row = mysql_fetch_array($result3)) {?> <tr> <td align="center"><?=$row['event_id']?></td> <td align="center"><?=$row['client_id']?></td> <td align="center"><?=$row['service_id']?></td> <td align="center"><?=$row['unit']?></td> <td align="center"><?=$row['quantity']?></td> <td align="center"><?=$row['event_start']?></td> <td align="center"><?=$row['event_end']?></td> <td align="center"><?=$row['fee']?></td> </tr> <?php } ?> </table> <br /> <table id="table" cellpadding="1px" cellspacing="1px" bordercolordark="#333"> <tr> <th bgcolor="#CCCCCC" align="center">Sub Total [£]</th> <th bgcolor="#CCCCCC" align="center">VAT [£]</th> <th bgcolor="#CCCCCC" align="center">Total [£]</th> </tr> <tr> <td align="center"><?php echo "$totalFee"?></td> <td align="center"><?php echo "$vat"?></td> <td align="center"><?php echo "$invoiceFee"?></td> </tr> </table> </body> </html> <?php $body = ob_get_contents(); ob_end_clean(); if(!mail($to, $subject, $body, $headers)){ die("Error sending message"); } $url = "Location: createInvoice.php?success=true";//mail sent header($url); exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/157138-solved-sending-my-html-page-using-php-mail-function/#findComment-829007 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.