Formatting my email sent with mail() through PHP, and IIS7 - php

First thing. My code works. I have my SMTP information set up correctly in IIS7's sendmail.ini, and i'm using gmail. What I have is a shopping cart for ordering food.
In my cart.php page, I have the print output pulling in the users choices:
$printoutput .= "<table width='500' border='0' cellspacing='0' cellpadding='0'>
<tr><td> <strong>Order Item # ". ($i+1) ."</strong></td></tr>
<tr><td> ". $product_name . "</td></tr>
<tr><td>$" . $price . ".00</td></tr>
<tr><td>". $displayoptions . "</td></tr></table>
<table height='1%' width='500' border='0' cellspacing='0' cellpadding='0'><tr><td></td></tr></table>";
$i++;
This output looks perfect in a web browser. Later in the code, I use a form to post the $printoutput and name it order. But on my email.php page, I use
session_start();
if(isset($_POST['order'])){
$order = $_POST['order'];
}
and then
mail($email_to, $email_subject, $order, $headers);
well like I said, I can just simply echo $order and it looks perfect in the web browser. But when actually sent as an email, I get an email with ALL of the html mark up with it. I've tried a few things, but nothing is formatting my information the way I want it to. Does anyone know how I can get this to basically format correctly in an email?
I'd like to have my information simply listed like this:
Order Item #
Product Name
Price
Options
But currently the output in the email has a ton of extra spaces, and shows all the HTML.
Any help would be appreciated.

http://www.w3schools.com/Php/func_mail_mail.asp
<?php
$to = "somebody#example.com, somebodyelse#example.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <webmaster#example.com>' . "\r\n";
$headers .= 'Cc: myboss#example.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>

Related

PHP email shows html source code in Apple Mail

I am sending an html email and the email shows perfectly fine everywhere except it shows the source code instead of the content in Apple mail.
Here is what I've done:
$to = "";
$subject = "";
$message = '
<html>
<head>
<title>New Inquiry From Quick Contact Form</title>
</head>
<body>
<table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="#F4F3F4">
<tbody>
<tr>
<td style="padding: 15px;">Name:</td>
</tr>
<tr>
<td style="padding: 15px;">Last Name:</td>
</tr>
</tbody>
</table>
</body>
</html>
';
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= 'From: "<support#mydomain>"' . "\r\n";
mail($to,$subject,$message,$headers);
Note: The HTML in my "message" variable above is just sample. I have a valid HTML in my actual development. I think I am doing something wrong with my headers.
Any help is highly appreciated!
Thanks,
Not sure, it it will help, but I would try to use phpmailer class, as it makes headers more accurate (google for download phpmailer class).
Also you can send e-mails using g-mail smtp server (google for php send email through gmail).

Mail generated using PHP mail function showing only code

I have written a code to send mail using PHP mail() function
$message = "
<html>
<head>
<title>TITLE</title>
</head>
<body>
<p>Customer ".$customerName." with id ".$customerId." wishes to place order for the following products that are currently note available in stock</p>
<table>
<tr>
<th align='center'>Product Name</th>
<th align='center'>Product Id</th>
<th align='center'>Product Part Number</th>
<th align='center'>Quantity</th>
</tr>"
.$content.
"
</table>
</body>
</html>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: '.$customerEmail.'' . "\r\n";
mail($to,$subject,$message,$headers);
The mail is working fine for me, but for the client it appears like this
From:
Sent: None
To: orders#xxxxx.com
Subject: SUBJECT
Content-type:text/html;charset=UTF-8
From: xxxx#xxxx.com
Message-Id: <20140908144611.165ACC36BC#SV08.xxxxxx.com>
Date: Mon, 8 Sep 2014 17:46:11 +0300 (AST)
X-Nonspam: None
X-Antivirus: avast! (VPS xxx-0, 09/09/2014), Inbound message
X-Antivirus-Status: Clean
<html>
<head>
<title>TITLE</title>
</head>
<body>
<p>Customer XXXX with id 3
wishes to place order for the following products that are currently not
available in stock</p>
<table>
<tr>
<th align='center'>Product Name</th>
<th align='center'>Product Id</th>
<th align='center'>Product Part Number</th>
<th align='center'>Quantity</th>
</tr><tr><td
align='center'>SCREW;BHHS;3/8-16 X .75</td><td align='center'>3237<td
align='center'>35059</td><td align='center'>6</td></tr>
</table>
</body>
</html>
Im not understanding why its working for our tests but not for the client. I tested using my gmail account and it shows fine where as the client is using his mail id on his company domain.
Instead of php mail function, I suggest you to use the phpMailer library with google mail smtp credentials. this will help you to send HTML template mails.
Reference URL - PHP mailer example url
Use the following header lines
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Remove and tags from your $message. And change headers to
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

HTML E-Mail as fileattachment

I have a Problem with Outlook 2010.
I sent an E-Mail with a Contactform with this Code:
$message = '
<html>
<head>
<title>Anfrage ('.$cfg->get('global.page.title').')</title>
<style type="text/css">
body { background:#FFFFFF; color:#000000; }
#tbl td {
background:#F0F0F0;
vertical-align:top;
}
#tbl2 td {
background:#E0E0E0;
vertical-align:top;
}
</style>
</head>
<body>
<p>Mail von der Webseite '.$cfg->get('global.page.title').'</p>
<table id="tbl">
<tr>
<td>Absender</td>
<td>'.htmlspecialchars($_POST['name']).' ('.htmlspecialchars(trim($_POST['email'])).')</td>
</tr>
<tr id="tbl2">
<td>Betreff:</td>
<td>'.htmlspecialchars($_POST["topic"]).'</td>
</tr>
<tr>
<td>Nachricht:</td>
<td>'.nl2br(htmlspecialchars($_POST["message"])).'</td>
</tr>
</table>
</body>
</html>';
$absender = $_POST['name'].' <'.$_POST['email'].'>';
$header = "From: $absender\n";
$header .= "Reply-To: $absender\n";
$header .= "X-Mailer: PHP/" . phpversion(). "\n";
$header .= "X-Sender-IP: " . $_SERVER["REMOTE_ADDR"] . "\n";
$header .= "Content-Type: text/html; Charset=utf-8";
$send_mail = mail($cfg->get('contact.toMailAdress'), "Anfrage (".$cfg->get('global.page.title').")", $message, $header);
//$send_mail = mail("jonathan.sigg#studcom.ch", "Anfrage (".$cfg->get('global.page.title').")", $message, $header);
$_SESSION['kontakt_form_time'] = time();
$tpl->assign("mail_sent", $send_mail);
When I sent the email, doesn't shows the message. it generates a File named [NAME].h. The Message is in this File. How can I fix that, that the message shows in the E-Mail. Is this a Problem about the settings in Outlook?
The problem is with your security settings in Outlook. You need to change the settings to display HTML.
Be careful though, other people trying to read this message will have the same problem. It's common courtesy to offer a plain text version in addition to a HTML version so those that receive these emails don't have to compromise their security settings for you. There's a good chance messages like this can be marked as Spam too.
Good luck.

How to send values from html form to mail in table PHP

This what I have I tried to put it in a table just like:
<table>
<tr><td>$_POST['onderwerp']</td></tr>
</table>
This is what I have it sends the mail but it's to messy:
<?php
$to = 'example#gmail.com';
$subject = 'Vraag via de website';
$message = 'Onderwerp:'. $_POST['onderwerp'].'<br /><br />'.$_POST['vraag'].'<br /><br />'.'Telefoonummer:'. $_POST['tel'].'<br /><br />'.'Email:'. $_POST['email'] ;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To:<eexample#gmail.com>' . "\r\n";
$headers .= 'The shop<example#gmail.com>' . "\r\n";
mail($to, $subject, $message, $headers);
header('Location: contact.html');
?>
I just want to send the variables in a table so that I don't have to search through all the text.
<?php
$to = 'user#example.com';
$subject = 'Vraag via de website';
$msg = "<html>
<head>
<title>Title of email</title>
</head>
<body>
<table cellspacing=\"4\" cellpadding=\"4\" border=\"1\" align=\"center\">
<tr>
<td align=\"center\">Onderwerp</td>
<td align=\"center\"> vraag</td>
<td align=\"center\">Telefoonummer</td>
<td align=\"center\">Email</td>
</tr>
<tr>
<td align=\"center\">".$_POST['onderwerp']."</td>
<td align=\"center\">".$_POST['vraag']."</td>
<td align=\"center\">".$_POST['tel']."</td>
<td align=\"center\">".$_POST['email']."</td>
</tr>
</table>
</body>
</html>";
// Make sure to escape quotes
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: My Site Name <me#mysite.com>' . "\r\n";
mail($to, $subject, $msg, $headers);
?>
you could try this using your variables.
$var = 'test';
$var2 = 'test2';
echo '<table border="1">';
echo '<tr><td>' . $var . '</td></tr>';
echo '<tr><td>' . $var . '</td></tr>';
echo '</table>';
this will show the variables in a table, then you can edit the table using css how you want. :)
I suggest that you include swiftmailer.
Swiftmailer makes sure emails get delivered in the Inbox and you can easily include HTML markup in your emails:
Swiftmailer HTML in email
Just download the Swiftmailer Library, include and configure it like this example:
Sending an email in swiftmailer
Let me know if this helps you out!

Php mail function table on right

I have tried several diffrent codes to have php send the form and have the mail alighned on right, and nothnig works. When I open the mail, it is always on left
<?php
$to = "skatz25#hotmail.com";
$subject = "טופס הפניית מתנדב/ גוף פונה";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$rname = $_POST['rname'];
$date = $_POST['date'];
$name = $_POST['name'];
$age = $_POST['age'];
$refrence = $_POST['refrence'];
$msg = '
<html>
<body dir="rtl">
<table dir="rtl" style="direction:rtl">
<tr>
<td style="text-align: right;">מקבל הפנייה:</td>
<td>' . $rname . '</td>
<tr>
</table>
</body>
<html>
';
mail($to, $subject, $msg, $headers);
?>
When I open the mail in hotmail the text is rtl but starts from the left side of the page instead of the right
Any help is appreciated
First, you must draw a table that has width and heigth set to 100% and in that table, create another table, aligned to the right, like: <table width='100%' height='100%'><tr><td align='right'> <table align='right'><tr><td>content</td></tr></table> </td></tr></table>
Try adding a width to the table.

Categories