i've looked everywhere online, and every guide seems to tell you how to set it up but not really tell you how the execution is nailed down. so i have a whole bunch of variables from a form via post. one variable, $order is a large querystring of HTML. it looks like this. <table align=\"center\" cellpadding=\"0\" border=\"0\"><tr><td><form action=\"cart.php?action=update\" method=\"post\" id=\"cart\"><table align=\"center\" cellpadding=\"10\" width=\"820\" border=\"0\"><tr><td style=\"border:1px solid #999;\"><a href=\"cart.php?action=delete&id=CSFT03CHI\" class=\"r\">Remove</a></td><td width=\"400\" style=\"border:1px solid #999;\">Men\'s 1/4 Zip Half Sleeve Pullover (albatross) in CHARCOAL/IVORY</td><td style=\"border:1px solid #999;\">$18.00</td><td width=\"50\" style=\"border:1px solid #999;\"><input type=\"text\" name=\"qtyCSFT03CHI\" value=\"11\" size=\"3\" maxlength=\"3\" /></td><td style=\"border:1px solid #999;\">$198.00</td></tr></table><p align=\"right\">Subtotal: <strong>$198.00</strong></p><div align=\"right\"><button type=\"submit\" id=\"mysubmit\">Update cart</button></div><p align=\"right\"><a href=\"memberindex.php\" >Back to Shopping...</a></p> </form></td></tr></table> Code (markup): the rest are simple strings to ID the sender. my submit code looks like this. <?php if(isset($_POST['submit'])) { $to = "xxx@gmail.com"; $name_field = $_POST['name']; $email_field = $_POST['email']; $message = $_POST['Comment']; $order = $_POST['order']; $subject = "New Order From $name_field"; $headers = "From: $name_field <order@xxx> \r\n"; $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message \n $order"; echo "Data has been submitted to $to!"; mail($to, $subject, $body, $headers); } else { echo "error: mail not delivered"; } ?> Code (markup): how do i format this so everything in $body shows up as html correctly in the email? now i know $order doesn't pass the validation right now, but all that needs to work is for me to see the the order...i wasn't thinking ahead when i added the function that spits out the $order querystring and now it's too late to change it.
I've tried the DIY approach and had problems getting my emails looking good in all email clients. Outlook, in particular, would break my links. My solution was to use phpMailer One hint when writing your html is to throw away classes and explicitly state which font, color, size etc.
If you want the message to be displayed as HTML then you could just set the content type in the header. <?php if(isset($_POST['submit'])) { $to = "xxx@gmail.com"; $name_field = $_POST['name']; $email_field = $_POST['email']; $message = $_POST['Comment']; $order = $_POST['order']; $subject = "New Order From $name_field"; $headers = "MIME-Version: 1.0\n"; $headers .= "Content-Type: text/html; charset=iso-8859-1\n"; $headers .= "From: $name_field <order@xxx>\n"; $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message \n $order"; echo "Data has been submitted to $to!"; if (mail($to, $subject, $body, $headers)) { } else { echo "error: mail not delivered"; } ?> PHP:
phpmailer isn't working for me. it cant seem to connect to send the mail. and i know the smtp server is the right one....man i can't catch a break. anything else i can do?
For reference for others, it is necessary to set the headers if you want HTML to be rendered in emails.