how to avoid spambox with php mail() function [duplicate] - php

This question already has answers here:
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Closed 6 years ago.
This is my first post. Yeah!
I got a problem with my contact form. it sends the email to my spambox.
How to avoid the spambox using php mail() function?
I already search on stackoverflow and serverfault but i can't seem to find the right solution....
This is the code that i am using.
<?php
if (isset($_POST['email'])
&& isset($_POST['name'])
&& isset($_POST['message'])
) {
$admin_email = "info#mywebsite.nl";
$name = htmlspecialchars($_POST['name']);
$phone = htmlspecialchars($_POST['phone']);
$email = htmlspecialchars($_POST['email']);
$subject = "Contact";
$comment = nl2br(htmlspecialchars($_POST['message']));
$to = $admin_email;
$headers = "From: " . $email . "\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$headers .= "Return-Path: The Sender <" . $admin_email . ">\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$message .= "<html>
<body style='margin: 0; padding: 0; font-family: Roboto Slab;'>
<table cellpadding='0' cellspacing='0' width='100%'>
<tr>
<td>
<table style='border: 1px solid #c7c5c5;' align='center' cellpadding='0' cellspacing='0' width='600' style='border-collapse: collapse;'>
<tr height='301'>
<td align='center' bgcolor='#ffffff' style='padding: 0 0 0 0;'>
<img src='myimage' alt='Contact' width='100%' height='100%' style='display: block;' />
</td>
</tr>
<tr>
<td bgcolor='#eee' style='padding: 40px 30px 40px 30px; background-color: #eee;'>
<table cellpadding='0' cellspacing='0' width='100%'>
<tr>
<td>
<h1 style='font-family: Roboto Slab;'>Contactinformation</h1>
</td>
</tr>
<tr>
<td style='padding: 20px 0 30px 0; font-family: Roboto Slab;'>
<b>From:</b> " . $naam . " <br/>
<b>E-mail:</b> " . $email . " <br/>
<b>Phone:</b> " . $phone . "
</td>
</tr>
<tr>
<td>
<h1 style='font-family: Roboto Slab;'>Message</h1>
</td>
</tr>
<tr>
<td style='padding: 20px 0 30px 0; font-family: Roboto Slab;'>
" . $comment . "
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor='#33333' style='padding: 30px 30px 30px 30px; background-color: #333;'>
<table cellpadding='0' cellspacing='0' width='100%'>
<td style='color: #fed136; font-family: Roboto Slab;' width='70%'>
Copyright ®
<a style='color: #fed136; font-family: Roboto Slab;' href=''></a> " . $thisyear . "<br/>
</td>
<td align='right'>
<table border='0' cellpadding='0' cellspacing='0'>
<tr>
<td>
<a style='color: #fed136; font-family: Roboto Slab;' href=''>
</a>
</td>
</tr>
</table>
</td>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>";
mail($to, $subject, $message, $headers);
}
?>
Many thanks in advance!

Some mail clients like gmail has certain rules to mark a mail as spam. If the mail subject or body containsfree/promo/offer/,etc. and it is not from a trusted sender, it will be marked as spam. Also such mail clients blacklist some senders and list it in spam box.
It happen to many big companies too.

Related

image not showing in email using php mail

I am trying to send email using php code mail is working file but image not coming into the mail. the image src path is coming with encoded string as below
<img style="width:100%" src="https://ci6.googleusercontent.com/proxy/NT6fQckS1LLRnuTUJnW0Fp2qUujk_Cpv9kV1hwoKQADwL8XU7fo4=s0-d-e1-ft#http://header.png" class="CToWUd a6T" tabindex="0">
<?php
$to = $_REQUEST['email'];
$subject = 'Winning prize';
$email_id = 'info#sample.com';
$headers = "From: " . strip_tags($email_id) . "\r\n";
$headers .= "Reply-To: " . strip_tags($email_id) . "\r\n";
$headers .= "CC: satishv#sample.com";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html>
<head>
<title></title>
</head>
<body>
<div style="border:1px solid #e96000; width: 600px;">
<table style="color: #777;font-family: sans-serif;" width="600">
<tr>
<td style="padding:0px 0">
<img style="width: 100%;" src="header.png">
</td>
</tr>
<tr>
<td><span style="font-family: sans-serif;">Hey</span><span style="font-family: sans-serif;margin-left: 5px;">'.$address['customer_name'].'!,</span></td>
</tr>
<tr>
<td style="padding:20px 0 0 20px"><span style="font-family: sans-serif;">Congratualtion! The product is Yours.</span></td>
</tr>
</table>
<table style="color: #777;font-family: sans-serif;text-align: center;" width="600">
<tr>
<td colspan="4" style="padding: 30px 0;border-top: 1px solid #e96000;border-bottom: 1px solid #e96000;"><span>Once Your Package ships we will send your a tracking number Once Your Package ships we will send your a tracking number Once Your Package ships we will send your a tracking number </span></td>
</tr>
</table>
</div>
</body>
</html>';
$result = mail($to, $subject, $message, $headers);
?>
the above code is working file just image not coming into the mail
Most of the email clients block the image. But still, you can show the image. You have to use Absolute image source URL. For an example
<img style="width: 100%;" src="header.png">
change to
<img style="width: 100%;" src="http://www.YourSite.com/header.png">
Please be sure that the image exists in the path.

PHP Curl to send SMS

I am pretty much at the beginner's level for PHP and cURL.
The issue is related to a php CronJob Script which fetches data from a phpmyadmin database relating to customer orders with a particular status (say "0", which means SMS not sent/or No Update Sent to Customer) and updating the shipping details.
Before adding the code to send SMS via API from my SMS Service Provider, the script was working fine which was being used to send emails, regarding shipping updates and following that, updating the database like Order Status and other necessary details to the customer as well as in the system.
The issue arises that if, suppose 100-150 results are fetched as
arrays with status='0' the loop only executes once and stops, whereas
before adding the SMS code, it used to run for n number rows
fetched with status='0'.
I've tried almost all the methods listed on StackOverflow, PHP Manuals, W3C as well as from the developer but still I'm unable to make it work successfully for all the results fetched.
Things I wan't -
1. Select data from a table where status='0'. **✓
2. Get details relating to the order using mysqli_fetch_array.✓
3. Send Email as per the format in the code.✓
4. Update Order History and Order Status.✓
5. Send an SMS using API as per the prescribed template. (⍻ Not Working)**
<?php
$con=mysqli_connect("localhost","admin","pass","database");//database connection
$get_email_contents = "SELECT * FROM `oc_shipping` WHERE `status`='0'";
date_default_timezone_set("Asia/Kolkata");
$date = date('Y-m-d');
if($data = mysqli_query($con,$get_email_contents))
{
while ($row=mysqli_fetch_array($data))
{
$order_id = $row['order_id'];
$tracking_no = $row['tracking_awb'];
$get_email = "SELECT * FROM `oc_order` WHERE `order_id`='$order_id'";
if($email_data = mysqli_query($con,$get_email))
{
while ($email_row=mysqli_fetch_array($email_data))
{
$email = str_replace(" ","",$email_row['email']);
$firstname = ucwords($email_row['firstname']);
$lastname = ucwords($email_row['lastname']);
$received_on = $email_row['date_added'];
$date_added = date("d M Y",strtotime($received_on));
$address_1 = $email_row['shipping_address_1'];
$address_2 = $email_row['shipping_address_2'];
$city = $email_row['shipping_city'];
$pincode = $email_row['shipping_postcode'];
$total = str_replace(".0000","",$email_row['total']);
$mobile = $email_row['telephone'];
$delivery_date = date('d-M-Y', strtotime($date. ' + 7 days'));
$track_url = "https://track.delhivery.com/p/".$tracking_no;
$text = "ABC.com
Hi ".$firstname.", Your Order ".$order_id." has been shipped via XYZ AWB #".$tracking_no.", which can be tracked on ".$track_url."
Expected delivery date is ".$delivery_date.". Please keep ready Rs.".$total."/- on the date of delivery.
Thank you for shopping on ABC.com";
echo "SMS Sent : ".$text."<br><br>";
$encode= rawurlencode($text);
//Just for my reference
$url= "login.smshub.com/api/mt/SendSMS?APIKey=****&senderid=ABCABC&channel=2&DCS=0&Route=1&Flashsms=0&Number=$mobile&Text=$encode";
$ch = curl_init("login.smshub.com/api/mt/SendSMS?APIKey=****&senderid=ABCABC&channel=2&DCS=0&Route=1&Flashsms=0&Number=$mobile&Text=$encode");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,"");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,TRUE);
$data = curl_exec($ch);
$json = json_decode($data);
$JobID = $json->{'JobId'};
$Error = $json->{'ErrorMessage'};
echo "Status : <strong>$JobID $Error </strong><br>";
//Email Receiver//
$to = "$email";
//From Header//
$header = "From: ABC.com<shipping#example.com>"."\r\n";
$header .= "MIME-Version: 1.0" . "\r\n";
$header .= "Content-type:text/html; charset=ISO-8859-1" . "\r\n";
// Subject //
$subject = "Your Order #$order_id has been Shipped";
// Message //
$message = "<html>
<head>
<title></title>
<link href='https://fonts.googleapis.com/css?family=Pacifico|Varela+Round' rel='stylesheet' />
</head>
<body>
<table align='center' cellpadding='1' style='background-color:#ffffff; border-color:#f3f3f3; border-radius:10px; border-size:1px; border-style:outset; max-width: 100%; width:100%; font-family: Helvetica,Arial,sans-serif; '>
<tbody>
<tr>
<td colspan='2' style='text-align:center'>
<p style='text-align:center'><a href='example.com' target='_blank'><img alt='abc.com' height='63' src='example.com/image/shipping/Logo.gif' width='250' /></a></p>
</td>
</tr>
<tr>
<td style='border-color:#f3f3f3; text-align:center; white-space:nowrap; width:50%'>
<p>Thank you for shopping on abc</p>
<h3 style='text-align:left;margin-left: 40px;'>Order Details</h3>
<table align='center' border='0' cellpadding='5' cellspacing='5' style='background-color:#f2f2f2; border-radius:5px; color:#333333; width:85%;'>
<tbody>
<tr>
<td>
<p style='text-align:left'>Order Number: <strong>$order_id</strong></p>
<p style='text-align:left'>Date Received: <strong>$date_added</strong></p>
<p style='text-align:left'>Name: <strong>$firstname $lastname</strong></p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td colspan='2' style='border-color:#f3f3f3; text-align:center'> </td>
</tr>
<tr>
<td colspan='2' style='border-color:#f3f3f3; text-align:center'>
<h3 style='text-align:left;margin-left: 40px;'>Delivery Address</h3>
<table align='center' border='0' cellpadding='5' style='background-color:#f2f2f2; border-radius:5px; color:#333333; padding:7px; width:85%;'>
<tbody>
<tr>
<td>
<p style='text-align:left'><strong>$address_1</strong></p>
<p style='text-align:left'><strong>$address_2</strong></p>
<p style='text-align:left'><strong>$city - $pincode</strong></p>
<p style='text-align:left'><strong>Mobile No. $mobile</strong></p>
</td>
</tr>
</tbody>
</table>
<p> </p>
</td>
</tr>
<tr>
<td colspan='2' style='text-align:center'>
<p style='text-align:center'><img alt='Order Shipped' height='90' src='example.com/image/shipping/Shipping.jpg' width='410' /></p>
<p>Your order has been shipped from our warehouse.</p>
<p>Amount Payable</p>
<h2>Rs.<strong>$total</strong></h2>
</td>
</tr>
<tr>
<td colspan='2' style='text-align:center;'>
<table align='center' border='0' cellpadding='1' cellspacing='1' style='background-color:#000000; border-radius:5px; color:#ffffff; font-size:larger; font-weight:700; padding:10px 15px; text-align:center; text-decoration:none; width:85%;'>
<tbody>
<tr>
<td><a href='https://track.xyz.com/p/$tracking_no' target='_blank' style='padding:15px 25px; text-align:center; text-decoration:none; color:#FFF; text-decoration:none;'>TRACK PACKAGE</a></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td colspan='2' style='text-align:center'>
<p><br />
</p>
</td>
</tr>
<tr>
<td colspan='2'>
<p style='text-align:center'><em><span style='font-size:12px'>Instructions</span></em></p>
<table align='center' border='0' cellspacing='5' style='background-color:#f2f2f2; border-radius:5px; color:#333333; width:85%;'>
<tbody>
<tr>
<td><span style='font-size:12px'>1.Please do not accept the package, if it is damaged / tampered before delivery.</span></td>
</tr>
<tr>
<td><span style='font-size:12px'>2.Your freebies (if any) shall be inside the package.</span></td>
</tr>
<tr>
<td><span style='font-size:12px'>3.Please mention remarks while signing for delivery, if you doubt that the package might be damaged or is suspicious.</span></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td colspan='2' style='text-align:center'>
<p> </p>
<p><span style='font-size:12px; color:#a9a9a9;'>Note: We do not demand your bank or credit card details over phone. Please do not divulge these details to fraudsters claiming to be calling on behalf of abc. </span></p>
<p> </p>
</td>
</tr>
<tr>
<td colspan='2' style='text-align:center'>
<p>Contact Us</p>
<p><strong><a href='mailto:help#abc.com?subject=Regarding%20Order%20ID%20$order_id' style='text-decoration:none; color:#000;'>help#example.com</a></strong></p>
<p><span style='font-size:10px; color:#a9a9a9;'>Do not reply to this email, this is an automated email sent to $email.</p>
</td>
</tr>
</tbody>
</table>
</body>
</html> \r\n";
//Send Mail//
$mail_send = mail($to,$subject,$message,$header);
if($mail_send)
{
$con=mysqli_connect("localhost","admin","pass","database");//database connection
$delete = "UPDATE `oc_ship` SET `status`='1' WHERE `order_id`='$order_id'";
if($deleted = mysqli_query($con,$delete))
{
$update_comment = mysqli_real_escape_string($con,"<p>Your order has been shipped via XYZ AWB #<b>$tracking_no</b>.</p> <p><a href='track.xyz.com/p/$tracking_no' target='_blank'>Click here to track your order</a></p>");
$date_time = date('Y-m-d H:i:s');
$order_history = "INSERT INTO `oc_order_hist`(`order_id`,`order_status_id`,`notify`,`comment`,`date_added`) VALUES ('$order_id','3','1','$update_comment','$date_time')";
if($order_history_update = mysqli_query($con,$order_history))
{
$order_status = "UPDATE `oc_order` SET `order_status_id`='3' WHERE `order_id`='$order_id'";
if($order_status_update = mysqli_query($con,$order_status))
{
echo "<br><strong>Shipping Updated successfully for Order ID $order_id</strong><br>";
}
}
}
}
}
}
}
}
?>
Since the script worked as expected until you added the SMS-sending code, that would imply that there's a problem with the new code.
Extract the SMS-sending code into a file on its own and test that, perhaps from the command line. Don't forget to check for cURL-specific errors (network errors, SSL error, etc.) with curl_error() and curl_errno(), like this:
$data = curl_exec($ch);
if (curl_errno($ch) > 0) {
print 'There was a cURL error: ' . $curl_error($ch);
}
Check the PHP and server logs also for error messages.

How to send email include html code using php? [duplicate]

This question already has an answer here:
How to send mail using php by insert html into mail content? [duplicate]
(1 answer)
Closed 7 years ago.
How to send email include html code using php ?
I tried to use this code.
<?PHP
include("connect.php");
$email = "test_mail#hotmail.com";
$to = $email;
$subject = "test subject";
$message = "
<body style='margin: 0; padding: 0;'>
<table border='1' cellpadding='0' cellspacing='0' width='100%'>
<tr>
<td>
<img src='http://i.stack.imgur.com/Jy9QUm.jpg'/>
</td>
</tr>
<tr>
<td>
test text
</td>
</tr>
</table>
</body>
";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: EXAMPLE <noreply#example.com>' . "\r\n";
$headers .= 'Return-Path: return#example.com' . "\r\n";
mail($to, $subject, $message, $headers, '-freturn#example.com');
?>
When i open my email it's will show like this in my email.
<body style='margin: 0; padding: 0;'>
<table border='1' cellpadding='0' cellspacing='0' width='100%'>
<tr>
<td>
<img src='http://i.stack.imgur.com/Jy9QUm.jpg'/>
</td>
</tr>
<tr>
<td>
test text
</td>
</tr>
</table>
</body>
But i want to show like this
How can i do ?
........................................................................................................................................................
Reason being is, that you don't have <!doctype html> and </html> tags (and other tags) and your HTML isn't being rendered as proper/full HTML markup.
$message = "
<!doctype html>
<html>
<head>
<title></title>
</head>
<body style='margin: 0; padding: 0;'>
<table border='1' cellpadding='0' cellspacing='0' width='100%'>
<tr>
<td>
<img src='http://i.stack.imgur.com/Jy9QUm.jpg'/>
</td>
</tr>
<tr>
<td>
test text
</td>
</tr>
</table>
</body>
</html>
";
Which upon testing afterwards, was successful.
Foonotes: (edit)
Even though I placed an answer, I decided to close the question being an exact duplicate of their other question How to send mail using php by insert html into mail content? where they were also nonrespondant and the answer given in there, answered what they posted for code.

What is wrong with my PHP email code; it won't redirect to thank you page [duplicate]

This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 9 years ago.
Curious as to what is wrong with the following php code which sends an email when a contact form is filled out and submitted. The email arrives perfectly but instead of redirecting it gives the following error:
Warning: Cannot modify header information - headers already sent by (output started at /home4/ranchoba/public_html/marvan/marvan/send.php:1) in /home4/ranchoba/public_html/marvan/marvan/send.php on line 112
I've tried calling the php file by the action in the form as well as by placing a in the very first line of the page. Neither one works.
PHP Code:
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
//if the form is submitted, go ahead and send the email to ops
ob_start();
if ($_POST['is_form_submitted'] == "yes")
{
//Send email to ops of this request-----------------------------------------------------------------------------------
// multiple recipients
$to = 'blah#gmail.com';
// subject
$subject = "Contact Request: ".$_POST['name'];
// message
$message = '
<html>
<head>
<title>Re: Marvan Site Contact Request</title>
<style type="text/css">
<!--
.style4 {font-family: Arial, Helvetica, sans-serif; font-size: 12; }
.style5 {font-size: 12}
.style6 {font-family: Arial, Helvetica, sans-serif; font-size: 12; font-weight: bold; }
-->
</style>
</head>
<body>';
$message=$message.'
<table width="450" border="0" align="center" cellpadding="4" cellspacing="0" style="border-color:#CCCCCC; border-style:solid; border-width:1px; background-color:#FFFFFF; padding-top:3px;">
<tr>
<td width="430" style="height:auto;" valign="top">';
$message=$message.'<img src="http://www.blah.com/blah/images/logo.png">';
$message=$message.'<hr>';
$message=$message.'<h2 style="font-family:Arial, Helvetica, sans-serif; color:#B58736">Contact Request </h2>';
$message=$message.'
<table width="486" border="0" align="center" cellpadding="4" cellspacing="2">
<tr>
<td colspan="4" valign="top"><div align="left" class="style4"><span style="color:#000000; font-weight:bold;">Contact Details: </span></div></td>
</tr>
<tr>
<td width="145" valign="top"><div align="left" class="style4">Name :</div></td>
<td width="1" valign="top"><span class="style5"></span></td>
<td width="984" colspan="2" valign="top"><div align="left" class="style6">';
$message = $message. $_POST['name'];
$message = $message.'</div></td>
</tr>
<tr>
<td valign="top"><div align="left" class="style4">Email :</div></td>
<td valign="top"><span class="style5"></span></td>
<td colspan="2" valign="top"><div align="left" class="style6">';
$message = $message. $_POST['email'];
$message = $message.'</div></td>
</tr>
<tr>
<td valign="top"><div align="left" class="style4">Subject :</div></td>
<td valign="top"><span class="style5"></span></td>
<td colspan="2" valign="top"><div align="left" class="style6">';
$message = $message. $_POST['subject'];
$message = $message.'</div></td>
</tr>
<tr>
<td valign="top"><div align="left" class="style4">Phone :</div></td>
<td valign="top"><span class="style5"></span></td>
<td colspan="2" valign="top"><div align="left" class="style6">';
$message = $message. $_POST['phone'];
$message = $message.'</div></td>
</tr>
<tr>
<td valign="top"><div align="left" class="style4">Message :</div></td>
<td valign="top"><span class="style5"></span></td>
<td colspan="2" valign="top"><div align="left" class="style6">';
$message = $message. $_POST['message'];
$message = $message.'</div></td>
</tr>';
$message = $message.'
<tr> <tr><td colspan="4" valign="top"><span class="style5"></span></td>
</tr>';
$message = $message.'
</table>
<br /></td>
</tr>
</table>
<p> </p>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
/* $headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";*/
/* $headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";*/
// Mail it
mail($to, $subject, $message, $headers);
//end of Send Email to Client --------------------------------------------------------------
//redirect to the thank you page
header('Location: http://www.blah.com/blah/thank-you.php');
} //end of if ($_POST['is_form_submitted'] == "yes")
?>
Maybe you have space before <?php tag in your scripts. Check it please and remove them. Also use UTF-8 file encoding without BOM
It is best to find where you are outputting a space or line that is causing the header() to fail. But if you cannot, try this to clear the buffer before header().
if (ob_get_length() > 0 ) {
ob_clean();
flush();
}

Changing php form to submit a styled email (HTML email)

When I submit my form, I receive the email in plain text and not quite in the format I'd like it to be. I'd like it to at least have color to the body and arrange the email so that its neater.
on the contact.php form ... this is what I currently have:
$msg = "You have been contacted by $name with regards to Accommodation.
They passed verification and their message is as follows." . PHP_EOL . PHP_EOL;
$msg .= "$comments" . PHP_EOL . PHP_EOL;
$msg .= "You can contact $name via email, $email or via phone $phone." .
PHP_EOL . PHP_EOL;
$msg .= "We want to stay from the $dayin to the $dayout" . PHP_EOL .
PHP_EOL;
Why is this form using $msg? I've seen in other forms, they use $message.
Can I add CSS styling to the above form?
I also see:
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
Would I need to change "plain" to "HTML"?
Any suggestions or examples would be great!
EDIT:
Ok so now my header are:
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . "\r\n" . PHP_EOL;
$headers .= "Content-type: text/html;charset=iso-8859-1" . "\r\n" .
PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
Do I need PHP_EOL in each header?
My $msg looks like:
$msg = '<style type="text/css">
<!--
.style {
font-family: Arial;
font-size: 12px;
color: #4D241E;
}
body {
background-image: url();
background-color: #F1EAE4;
}
.style1 {font-size: 14px}
-->
</style>
<p> </p>
<table width="420" border="0" align="center" cellpadding="0" cellspacing="5">
<tr>
<td><table width="100%" border="0" cellpadding="8" cellspacing="0" bgcolor="#E7D3AF"
class="style">
<tr>
<td colspan="2" valign="top"><div align="center"><strong><span
class="style1">Submission / Enquiry from your website</span><br>
........................................................................
</strong><br>
</div></td>
</tr>
<tr>
<td width="32%" valign="top"><div align="left"><strong>Date Submitted</strong>
</div></td>
<td width="68%" valign="top">'. date("F j, Y, g:i a") .'</td>
</tr>
<tr>
<td valign="top"><div align="left"><strong>Name</strong></div></td>
<td valign="top">'.$_POST['name'].'</td>
</tr>
<tr>
<td valign="top"><div align="left"><strong>Email</strong></div></td>
<td valign="top">'.$_POST['email'].'</td>
</tr>
<tr>
<td valign="top"><div align="left"><strong>Phone</strong></div></td>
<td valign="top">'.$_POST['phone'].'</td>
</tr>
<tr>
<td valign="top"><div align="left"><strong>Day in</strong></div></td>
<td valign="top">'.$_POST['dayin'].'</td>
</tr>
<tr>
<td valign="top"><div align="left"><strong>Day out</strong></div></td>
<td valign="top">'.$_POST['dayout'].'</td>
</tr>
<tr>
<td valign="top"><div align="left"><strong>Comments</strong></div></td>
<td valign="top">'.$_POST['comments'].'</td>
</tr>
</table></td>
</tr>
</table>
';
EDIT:
MY NEW HTML EMAIL DESIGN:
<table width="600" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="12" height="14"></td>
<td width="140"></td>
<td width="432"></td>
<td width="16"></td>
</tr>
<tr>
<td height="71"></td>
<td colspan="2" align="center" valign="middle" bgcolor="#F5F5F5"><span style="font-
family:Arial; font-size:18px; color:#333333;"><strong>Submission from</strong>
</span><br />
<span style="font-family:Arial; font-size:16px; color:#f9930f;">
<em>Your website</em></span></td>
<td></td>
</tr>
<tr>
<td height="16"></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="30"></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px; color:#333333;">
<strong>Name:</strong></span></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px;
color:#333333;">'.$_POST['name'].'</span></td>
<td></td>
</tr>
<tr>
<td height="30"></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px; color:#333333;">
<strong>Email:</strong></span></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px;
color:#333333;">'.$_POST['email'].'</span></td>
<td></td>
</tr>
<tr>
<td height="30"></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px; color:#333333;">
<strong>Phone:</strong></span></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px;
color:#333333;">'.$_POST['phone'].'</span></td>
<td></td>
</tr>
<tr>
<td height="30"></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px; color:#333333;">
<strong>Day in:</strong></span></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px;
color:#333333;">'.$_POST['dayin'].'</span></td>
<td></td>
</tr>
<tr>
<td height="30"></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px; color:#333333;">
<strong>Day out:</strong></span></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px;
color:#333333;">'.$_POST['dayout'].'</span></td>
<td></td>
</tr>
<tr>
<td height="30"></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px; color:#333333;">
<strong>Comments:</strong></span></td>
<td> </td>
<td></td>
</tr>
<tr>
<td height="190"></td>
<td colspan="2" valign="top"><span style="font-family:Arial; font-size:12px;
color:#333333;">'.$_POST['comments'].'</span></td>
<td></td>
</tr>
<tr>
<td height="20"></td>
<td> </td>
<td> </td>
<td></td>
</tr>
</table>
Now when I add this form in my php and submit my form ... I receive my submission that doesn't look like the table layout like above.
You can use the following headers. These will allow you to just put normal HTML in your message.
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <example#example.com>' . "\r\n";
$headers .= 'Cc: example two#example.com' . "\r\n";
Yep you are going to have to use
Content-type:text/html;charset=iso-8859-1\r\n
It might be a good idea to provide your email in both HTML and text formats as not all email applications support HTML, and many others support it poorly.
To do so use this header instead. The boundary thing is what separates the HTML and text versions in the email, the line below generates a unique code which is suitable for this purpose
$boundary = md5(date('r', time()));
$headers .= "\r\nContent-Type: multipart/alternative; boundary=$boundary."\"";
Before the text version of the email post this code, note the "--" at the begging. You use the same boundary throughout the email.
--<?php echo $boundary; ?>
Before the HTML version post the same code again
There is a good template you can use here
http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php

Categories