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.
Related
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.
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.
I have a VPS with inmotion hosting, and i send a confirmation email, but the email it takes too mucho to send, how is the best way to estructure the html code when i send a mail, how can i boost the performance.
This is my code.
$subject = 'Mail activation';
$body = '
<html>
<head>
<base target="_blank">
</head>
<body>
<table style="max-width:800px; margin:0 auto; font-family: Arial, Helvetica, sans-serif;" cellspacing="0" cellpadding="10">
<thead style="border-bottom:1px solid #DDD;">
<tr>
<td align="center" style="border-bottom:1px solid #DDD;">
<img src="http://p.unid.com/img/logoSASENegro.png" alt="" height="45" width="150"/>
</td>
</tr>
</thead>
<tbody>
<tr>
<td>
Hi classmate
</td>
</tr>
<tr>
<td>
Press the following link.
</td>
</tr>
<tr>
<td>
www.google.com
</td>
</tr>
<tr>
<td>
You data:
</td>
</tr>
<tr>
<td>
ID - <b>'.$ids.'</b><br/>
Password - <b>'.$pass.'</b><br/>
</td>
</tr>
<tr>
<td>
Don't response this email.
</td>
</tr>
</tbody>
</table>
</body>
</html>
';
$headers = "MIME-Version: 1.0\r\n";
$headers .="Content-type: text/html; charset=utf-8\r\n";
$headers .= "From: Contacto SASE <atencionsase#unid.mx>\r\n";
if(mail($emailC, $subject, $body, $headers))
On some servers mail() sent emails really slow. Your issue is not related to message content, but it related to your hosting provider. As a possible solution, you can just switch your script to sending mail via different SMTP server (for example gmail: Send email using the GMail SMTP server from a PHP page).
I have PHP mailer script and I am trying to add HTML table into it but when I do the script stops working.
Here's the PHP mailer script
<?php
// Insert your email/web addresses and correct paths
$mailto = 'adil#*******.co.uk' ;
$from = "web#city.com" ;
$subject = "Query from ******* 2012";
$headers = "From: ******* Website";
$formurl = "http://*******.co.uk/citycoaches3/formmail.php" ;
$errorurl = "http://*******.co.uk/citycoaches3/error.php" ;
$thankyouurl = "http://*******.co.uk/citycoaches3/thankyou.php" ;
// Place Your Form info here...
$pickuppoint = ($_POST['pickuppoint']);
$destination = ($_POST['destination']);
// Check If Empty
// Add more Validation/Cleaning here...
// Place your Corresponding info here...
$message =
"Pick Point: $pickuppoint\n\n" .
"Destination: $destination\n\n" .
"noppl: $noppl\n\n"
;
// Leave Alone
mail($mailto, $from, $message);
header( "Location: $thankyouurl" );
exit ;
?>
Any help on this will be appreciated.
Heres what i tried
<?php
$fromAddr = 'adil#********.co.uk'; // the address to show in From field.
$recipientAddr = 'quotes#********.co.uk';
$subjectStr = '[Quick] Query From ********';
$date = date ("l, F jS, Y");
$time = date ("h:i A");
$forward = 1;
$formurl = "http://www.********.co.uk/formmail.php" ;
$errorurl = "http://www.********.co.uk/error.php" ;
$thankyouurl = "http://www.********.co.uk/thankyou.php" ;
header("location:thankyou.php");
$mailBodyText = <<<HHHHHHHHHHHHHH
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Thank You</title>
</head>
<body>
<img src="http://********.co.uk/images/mailsig.png" /> \n\n<br />
<span style="color:#900; font-size:18px;">Below is the result submitted from <strong>[Quick Quote] ******** Website</strong>. It was submitted on <strong>$date at $time</strong>.\n\n</span>
<p><table width="600" border="1" cellpadding="5px">
<tr>
<td><b>Pickup Date:</b> </td>
<td>{$_POST['date']}<br></td>
</tr>
<tr>
<td><b>Pickup Time:</b> </td>
<td>{$_POST['PickupTime-Hours']}:{$_POST['PickupTime-Mins']}<br></td>
</tr>
<tr>
<td><b>Pickup Point:</b> </td>
<td>{$_POST['PickUp-Point']}<br></td>
</tr>
<tr>
<td><b>Destination:</b> </td>
<td>{$_POST['Destination']}<br></td></tr>
<tr>
<td><b>No. Of People:</b> </td>
<td>{$_POST['No-of-Persons']}<br></td>
</tr>
<tr>
<td><b>Journey Type:</b> </td>
<td>{$_POST['JourneyType']}<br></td>
</tr>
<tr>
<tr>
<td><b>Return Date:</b> </td>
<td>{$_POST['returnDate']}<br></td>
</tr>
<tr>
<td><b>Return Time:</b> </td>
<td>{$_POST['returnTime-Hours']}{$_POST['returnTime-Mins']}<br></td>
</tr>
<tr>
<tr>
<td><b>Vehicle Type:</b> </td>
<td>{$_POST['type']}<br></td>
</tr>
<tr>
<tr>
<td><b>Full Name:</b> </td>
<td>{$_POST['Full-Name']}<br></td>
</tr>
<tr>
<tr>
<td><b>Tel / Mobile:</b> </td>
<td>{$_POST['Tel-Mobile']}<br></td>
</tr>
<tr>
<td><b>Email:</b> </td>
<td>{$_POST['Email']}<br></td>
</tr>
<tr>
</table>
</p>
</body>
</html>
HHHHHHHHHHHHHH;
$headers= <<<TTTTTTTTTTTT
From: $fromAddr
MIME-Version: 1.0
Content-Type: text/html;
TTTTTTTTTTTT;
mail($mailto, $from, $message,
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep );
header( "Location: $thankyouurl" );
exit ;
?>
Still doesn't work for some reason.
Heres the UPDATE:
After removing
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" .
I managed to receive the email, but it pasted the whole code which is in $message.
Try getting the HTML from a file :
$message = file_get_contents('./path/email.html') // it's easyer to maintain but not mandatory
And add a html content type header
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
then
mail($mailto, $from, $message, $headers) //notice the headers;
As I think the others answers didn't gave you the correct direction yet, here's my addition:
$name = _("test"); // Or insert variable
$message = <<<EOF
// html here
<p>hello $name</p>
EOF;
$to = "";
$subject = "";
// 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 .= 'From: Example <info#example.com>' . "\r\n";
// Mail it
mail($to, $subject, $email, $headers);
You'll need the html headers when sending the email..
ALL thank you very much for your help and suggestions.
I finally got it working here is what I did.
In $message in inserted:
$message = "<html><body>
<b><FONT COLOR='#900' SIZE='13px'>Hi this is working now</FONT></b>
<table width='400' border='0' cellpadding='5px'>
<tr>
<td><b><FONT COLOR='#900'>Pickup Date:</FONT></b> </td>
<td>{$_POST['date']}<br></td>
</tr>
</table>
</html></body>";
And added following headers
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
All working thanks everyone again!
Use php html email and insert table in email body part
If you want to display the messagebody in your message to your recipient, maybe you should try putting a quotation mark in your code:
$mailBodyText = "<<<HHHHHHHHHHHHHH
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Thank You</title>
</head>
<body>
<img src="http://********.co.uk/images/mailsig.png" /> \n\n<br />
<span style="color:#900; font-size:18px;">Below is the result submitted from <strong> [Quick Quote] ******** Website</strong>. It was submitted on <strong>$date at $time</strong>.\n\n</span>
<p><table width="600" border="1" cellpadding="5px">
<tr>
<td><b>Pickup Date:</b> </td>
<td>{$_POST['date']}<br></td>
</tr>
<tr>
<td><b>Pickup Time:</b> </td>
<td>{$_POST['PickupTime-Hours']}:{$_POST['PickupTime-Mins']}<br></td>
</tr>
<tr>
<td><b>Pickup Point:</b> </td>
<td>{$_POST['PickUp-Point']}<br></td>
</tr>
<tr>
<td><b>Destination:</b> </td>
<td>{$_POST['Destination']}<br></td></tr>
<tr>
<td><b>No. Of People:</b> </td>
<td>{$_POST['No-of-Persons']}<br></td>
</tr>
<tr>
<td><b>Journey Type:</b> </td>
<td>{$_POST['JourneyType']}<br></td>
</tr>
<tr>
<tr>
<td><b>Return Date:</b> </td>
<td>{$_POST['returnDate']}<br></td>
</tr>
<tr>
<td><b>Return Time:</b> </td>
<td>{$_POST['returnTime-Hours']}{$_POST['returnTime-Mins']}<br></td>
</tr>
<tr>
<tr>
<td><b>Vehicle Type:</b> </td>
<td>{$_POST['type']}<br></td>
</tr>
<tr>
<tr>
<td><b>Full Name:</b> </td>
<td>{$_POST['Full-Name']}<br></td>
</tr>
<tr>
<tr>
<td><b>Tel / Mobile:</b> </td>
<td>{$_POST['Tel-Mobile']}<br></td>
</tr>
<tr>
<td><b>Email:</b> </td>
<td>{$_POST['Email']}<br></td>
</tr>
<tr>
</table>";
I am sending an automatic email via php. The email contains Hebrew which direction is right to left. Here is my code for making up the body part of the message:
$emailMessage ='
<html lang="HE">
<head>
<title>
job-skills | הצורפות
</title>
</head>
<body style="text-align:right; direction:rtl;">
<table>
<tr>
<td><h3>תודה על הצטרפותך</h4></td>
</tr>
<tr>
<td>על מנת להצטרף סופית לאתר עליך ללחץ על הלינק הבא:</td>
</tr>
<tr>
<td><a href="http://localhost/W-DB/php/registration_and_login/confirm_registration.php?email=' .$registrationEmail .'&tempPass=' . $tempPass . '>לחץ כאן</a></td>
<tr>
</tr>
<tr>
<td>בברכה,</td>
</tr>
<tr>
<td><h2>JOb-Skills</h2></td>
</tr
</table>
</body>
</html>
still the text aligned to left and direction left to right.
Here is my code:
<?php
$to ="mail id";
$from = "mail id";
$sub = "Hebrew";
$message = '<html lang="HE">
<head>
<title>
job-skills | הצורפות
</title>
</head>
<body style="text-align:right; direction:rtl;">
<table>
<tr>
<td><h3>תודה על הצטרפותך</h4></td>
</tr>
<tr>
<td>על מנת להצטרף סופית לאתר עליך ללחץ על הלינק הבא:</td>
</tr>
<tr>
<td>
לחץ כאן</td>
<tr>
</tr>
<tr>
<td>בברכה,</td>
</tr>
<tr>
<td><h2>JOb-Skills</h2></td>
</tr
</table>
</body>
</html>';
$headers = "From:" . $from;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
if(mail($to,$sub,$message,$headers)) echo "success";
?>
Try adding dir="rtl" to your HTML tag.
Please refer to style #Varun placed in the body: <body style="text-align:right; direction:rtl;">
Only after I added this style to the body it worked also on gmail, until then It was working only on Outlook.
It is working fine with the code I mentioned. Please have a look to the attached image.