Hi there, I have an email form and I need the contents of the message to be the output of the page. Here is my code: <?php $to = "name@ips.com"; $subject = "HTML email"; $message = ""; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; // More headers $headers .= "From: sender@isp.com\r\n" . "X-Mailer: php"; mail($to,$subject,$message,$headers); ?> <html> <table border="1"> <tr><td colspan="2"><b>Enquiry Details</b></td></tr> <tr><td width="140">Arrival Date:</td><td width="360"><?php echo $_POST["date_day"]; ?>/<?php echo $_POST["date_month"]; ?>/<?php echo $_POST["date_year"]; ?></td></tr> <tr><td>Departure Date:</td><td><?php echo $_POST["dateto_day"]; ?>/<?php echo $_POST["dateto_month"]; ?>/<?php echo $_POST["dateto_year"]; ?></td></tr> <tr><td>Rooms required:</td><td><?php echo $_POST["single"]; ?> Single Room(s), <?php echo $_POST["double"]; ?> Double Room(s), <?php echo $_POST["twin"]; ?> Twin Room(s)</td></tr> <tr><td>Party Size:</td><td><?php echo $_POST["adults"]; ?> Adult(s), <?php echo $_POST["children"]; ?> Children</td></tr> <tr><td>Age(s) of Children:</td><td><?php echo $_POST["childrenage"]; ?></td></tr> <tr><td>Message:</td><td><?php echo nl2br($_POST[message]) ?></td></tr> <tr><td colspan="2"><b>Enquiry Details</b></td></tr> <tr><td>First Name:</td><td><?php echo $_POST["firstname"]; ?></td></tr> <tr><td>Last Name:</td><td><?php echo $_POST["lastname"]; ?></td></tr> <tr><td>Email:</td><td><?php echo $_POST["email"]; ?></td></tr> <tr><td>Phone:</td><td><?php echo $_POST["phone"]; ?></td></tr> <tr><td>Fax:</td><td><?php echo $_POST["fax"]; ?></td></tr> <tr><td>Address:</td><td><?php echo $_POST["addressline1"]; ?><br /> <?php echo $_POST["addresline2"]; ?></td></tr> <tr><td>City:</td><td><?php echo $_POST["city"]; ?></td></tr> <tr><td>Country:</td><td><?php echo $_POST["country"]; ?></td></tr> </table> </html>"; PHP: So I need all the HTML code at the bottom to be in the $message. How do I do this because what I have tried so far only results in fails. Thanks in advance!
use concat equals $message = "line 1"; $message .= "line 2"; $message .= "line 3"; etc...... echo $message;
So I used: <?php $to = "name@ips.com"; $subject = "HTML email"; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; // More headers $headers .= "From: sender@isp.com\r\n" . "X-Mailer: php"; mail($to,$subject,$message,$headers); $message = "<html>"; $message .= "<table border="1">"; $message .= "<tr><td colspan="2"><b>Enquiry Details</b></td></tr>"; $message .= "<tr><td width="140">Arrival Date:</td><td width="360"><?php echo $_POST["date_day"]; ?>/<?php echo $_POST["date_month"]; ?>/<?php echo $_POST["date_year"]; ?></td></tr>"; $message .= "<tr><td>Departure Date:</td><td><?php echo $_POST["dateto_day"]; ?>/<?php echo $_POST["dateto_month"]; ?>/<?php echo $_POST["dateto_year"]; ?></td></tr>"; $message .= "<tr><td>Rooms required:</td><td><?php echo $_POST["single"]; ?> Single Room(s), <?php echo $_POST["double"]; ?> Double Room(s), <?php echo $_POST["twin"]; ?> Twin Room(s)</td></tr>"; $message .= "<tr><td>Party Size:</td><td><?php echo $_POST["adults"]; ?> Adult(s), <?php echo $_POST["children"]; ?> Children</td></tr>"; $message .= "<tr><td>Age(s) of Children:</td><td><?php echo $_POST["childrenage"]; ?></td></tr>"; $message .= "<tr><td>Message:</td><td><?php echo nl2br($_POST[message]) ?></td></tr>"; $message .= "<tr><td colspan="2"><b>Enquiry Details</b></td></tr>"; $message .= "<tr><td>First Name:</td><td><?php echo $_POST["firstname"]; ?></td></tr>"; $message .= "<tr><td>Last Name:</td><td><?php echo $_POST["lastname"]; ?></td></tr>"; $message .= "<tr><td>Email:</td><td><?php echo $_POST["email"]; ?></td></tr>"; $message .= "<tr><td>Phone:</td><td><?php echo $_POST["phone"]; ?></td></tr>"; $message .= "<tr><td>Fax:</td><td><?php echo $_POST["fax"]; ?></td></tr>"; $message .= "<tr><td>Address:</td><td><?php echo $_POST["addressline1"]; ?><br />"; $message .= " <?php echo $_POST["addresline2"]; ?></td></tr>"; $message .= "<tr><td>City:</td><td><?php echo $_POST["city"]; ?></td></tr>"; $message .= "<tr><td>Country:</td><td><?php echo $_POST["country"]; ?></td></tr>"; $message .= "</table>"; $message .= "</html>"; ?> PHP: And I got: Parse error: syntax error, unexpected T_LNUMBER in process.php on line 19
You might need to turn off Notices if you get any <?php $to = "name@ips.com"; $subject = "HTML email"; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; // More headers $headers .= "From: sender@isp.com\r\n" . "X-Mailer: php"; mail($to,$subject,$message,$headers); $message = "<html>"; $message .= "<table border=\"1\">"; $message .= "<tr><td colspan=\"2\"><b>Enquiry Details</b></td></tr>"; $message .= "<tr><td width=\"140\">Arrival Date:</td><td width=\"360\"><?php echo $_POST[date_day]; ?>/<?php echo $_POST[date_month]; ?>/<?php echo $_POST[date_year]; ?></td></tr>"; $message .= "<tr><td>Departure Date:</td><td><?php echo $_POST[dateto_day]; ?>/<?php echo $_POST[dateto_month]; ?>/<?php echo $_POST[dateto_year]; ?></td></tr>"; $message .= "<tr><td>Rooms required:</td><td><?php echo $_POST[single]; ?> Single Room(s), <?php echo $_POST[double]; ?> Double Room(s), <?php echo $_POST[twin]; ?> Twin Room(s)</td></tr>"; $message .= "<tr><td>Party Size:</td><td><?php echo $_POST[adults]; ?> Adult(s), <?php echo $_POST[children]; ?> Children</td></tr>"; $message .= "<tr><td>Age(s) of Children:</td><td><?php echo $_POST[childrenage]; ?></td></tr>"; $message .= "<tr><td>Message:</td><td><?php echo nl2br($_POST[message]) ?></td></tr>"; $message .= "<tr><td colspan=\"2\"><b>Enquiry Details</b></td></tr>"; $message .= "<tr><td>First Name:</td><td><?php echo $_POST[firstname]; ?></td></tr>"; $message .= "<tr><td>Last Name:</td><td><?php echo $_POST[lastname]; ?></td></tr>"; $message .= "<tr><td>Email:</td><td><?php echo $_POST[email]; ?></td></tr>"; $message .= "<tr><td>Phone:</td><td><?php echo $_POST[phone]; ?></td></tr>"; $message .= "<tr><td>Fax:</td><td><?php echo $_POST[fax]; ?></td></tr>"; $message .= "<tr><td>Address:</td><td><?php echo $_POST[addressline1]; ?><br />"; $message .= " <?php echo $_POST[addresline2]; ?></td></tr>"; $message .= "<tr><td>City:</td><td><?php echo $_POST[city]; ?></td></tr>"; $message .= "<tr><td>Country:</td><td><?php echo $_POST[country]; ?></td></tr>"; $message .= "</table>"; $message .= "</html>"; ?> PHP:
@MyVodafone You should'nt include php tags within a concatenated string (especially in this case), its bad coding, dirty and unefficient, use output buffering as its not only easier but more effective. <?php $to = "name@ips.com"; $subject = "HTML email"; $message = ""; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; // More headers $headers .= "From: sender@isp.com\r\n" . "X-Mailer: php"; ob_start(); $_POST = array_map('strip_tags', $_POST); ?> <html> <table border="1"> <tr><td colspan="2"><b>Enquiry Details</b></td></tr> <tr><td width="140">Arrival Date:</td><td width="360"><?php echo $_POST["date_day"]; ?>/<?php echo $_POST["date_month"]; ?>/<?php echo $_POST["date_year"]; ?></td></tr> <tr><td>Departure Date:</td><td><?php echo $_POST["dateto_day"]; ?>/<?php echo $_POST["dateto_month"]; ?>/<?php echo $_POST["dateto_year"]; ?></td></tr> <tr><td>Rooms required:</td><td><?php echo $_POST["single"]; ?> Single Room(s), <?php echo $_POST["double"]; ?> Double Room(s), <?php echo $_POST["twin"]; ?> Twin Room(s)</td></tr> <tr><td>Party Size:</td><td><?php echo $_POST["adults"]; ?> Adult(s), <?php echo $_POST["children"]; ?> Children</td></tr> <tr><td>Age(s) of Children:</td><td><?php echo $_POST["childrenage"]; ?></td></tr> <tr><td>Message:</td><td><?php echo nl2br($_POST["message"]) ?></td></tr> <tr><td colspan="2"><b>Enquiry Details</b></td></tr> <tr><td>First Name:</td><td><?php echo $_POST["firstname"]; ?></td></tr> <tr><td>Last Name:</td><td><?php echo $_POST["lastname"]; ?></td></tr> <tr><td>Email:</td><td><?php echo $_POST["email"]; ?></td></tr> <tr><td>Phone:</td><td><?php echo $_POST["phone"]; ?></td></tr> <tr><td>Fax:</td><td><?php echo $_POST["fax"]; ?></td></tr> <tr><td>Address:</td><td><?php echo $_POST["addressline1"]; ?><br /> <?php echo $_POST["addresline2"]; ?></td></tr> <tr><td>City:</td><td><?php echo $_POST["city"]; ?></td></tr> <tr><td>Country:</td><td><?php echo $_POST["country"]; ?></td></tr> </table> </html> <?php $message = ob_get_clean(); mail($to,$subject,$message,$headers); ?> PHP:
Another way, which is good in the beginning, when things don't work is to define the $_POST['xxx'] as variables: $name=$_POST['name']; $address=$_POST['address']; ... etc. Code (markup): then include it in the code as this: $msg= ' <html> <table border="1"> <tr><td colspan="2"><b>' . $name . '</b></td></tr> ... etc Code (markup): This is just an alternative way for easier keeping track of the variables in the beginning...