PHP mail send very slowly - php

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).

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.

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();
}

How do you make an email go to spam

I am writing a script for a film. I have a basic script that sends an HTML email to two sets of emails. On the form you enter in the event information and that information gets sent to two lists of users, the "Desired Guests" and the "Undesired Guests" they both get the same exact HTML email however I need the email for the "Undesired Guests" to go to the spam folder. So what I did was for the "Undesired Guest" email list was insert a bunch of spam content into the body of the email as I need this email to send to the spam folder. The "Desired Guests" email should go to the inbox just fine (as is currently is)
Is there any way I can make the "Undesired Guests" email to go spam for sure? Can I send the email through an outside server with a different IP and bad reputation to make these emails go to spam?
Any input would be a great help.
<?php
if(isset($_POST['submit'])) {
$event = strtoupper($_POST['event']);
$host = strtoupper($_POST['host']);
$location = strtoupper($_POST['location']);
$date = $_POST['date'];
$start_time = $_POST['start_time'];
$end_time = $_POST['end_time'];
$msg = ucfirst($_POST['msg']);
$mainuser = $_POST['mainuser'];
$wrong_user = $_POST['wrong_user'];
if($mainuser!='') {
$user_mail = explode(",", $mainuser);
$count = count($user_mail);
$sub = "You're Invited";
$sender = "info#cdell.me";
for($i=0;$i<$count;$i++){
$mail_to = $user_mail[$i];
$mail_body =
'<style type="text/css">
<!--
.style1 {color: #8f8f8f}
-->
</style>
</head>
<body style="font-family:Arial, Helvetica, sans-serif; background:#f5f5f5; line- height:24px;">
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
<tr>
<td><img src="http://www.cdell.me/invite-site/header.png" width="600" height="200" /></td>
</tr>
<tr>
<td height="50" bgcolor="#ececec"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
</tr>
</table></td>
</tr>
<tr>
<td bgcolor="#e0e0e0" style="padding:20px; font-size:16px; color:#8f8f8f" align="center">
<p><strong>'.$event.'</strong></p>
<p><strong>When:</strong> '.$date.' '.$start_time.' - '.$end_time.'</p>
<p><strong>Where:</strong> '.$location.'</p>
<p><strong>Message From '.$host.':</strong> <br /> '.$msg.'</p><br /><br /></td>
</tr>
<tr>
<td bgcolor="#e0e0e0" align="center">RSVP!</td>
</tr>
<tr>
<td height="30" bgcolor="#e0e0e0"> </td>
</tr>
<tr>
<td height="40"> </td>
</tr>
<tr>
<td><table width="520" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="5" style="border-bottom:solid 1px #2ecc71"> </td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><table width="600" border="0" cellpadding="0" cellspacing="0" bgcolor="#2ecc71">
<tr>
<td width="40"> </td>
<td width="240"> </td>
<td width="40"> </td>
<td width="240"> </td>
<td width="40"> </td>
</tr>
<td width="40"> </td>
<td width="240"> </td>
<td width="40"> </td>
<td width="240"> </td>
<td width="40"> </td>
</tr>
</table></td>
</tr>
</table>
</body>';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "to:".$ro['emai_addrs']."\r\n";
$headers .= "from: ".$sender."\r\n";
mail($mail_to, $sub, $mail_body, $headers);
//echo $mail_body;
}
}
if($wrong_user!='') {
$user_mail=explode(",", $wrong_user);
$count=count($user_mail);
$sub="INVITATION";
$sender="";
for($i=0;$i<$count;$i++) {
$mail_to = $user_mail[$i];
$mail_body =
'<style type="text/css">
<!--
.style1 {color: #8f8f8f}
-->
</style>
</head>
<body style="font-family:Arial, Helvetica, sans-serif; background:#f5f5f5; line-height:24px;">
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
<tr>
<td><img src="http://www.cdell.me/invite-site/header.png" width="600" height="200" /></td>
</tr>
<tr>
<td height="50" bgcolor="#ececec"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
</tr>
</table></td>
</tr>
<tr>
<td bgcolor="#e0e0e0" style="padding:20px; font-size:16px; color:#8f8f8f" align="center">
<p><strong>'.$event.'</strong></p>
<p><strong>When:</strong> '.$date.' '.$start_time.' - '.$end_time.'</p>
<p><strong>Where:</strong> '.$location.'</p>
<p><strong>Message From '.$host.':</strong> <br /> '.$msg.'</p><br /><br /></td>
</tr>
<tr>
<td bgcolor="#e0e0e0" align="center">RSVP!</td>
</tr>
<tr>
<td height="30" bgcolor="#e0e0e0"> </td>
</tr>
<tr>
<td height="40" style="color:white;"> 9 INCH PENIS, SPAM EMAIL, THIS IS SPAM, 10 INCH PENIS, VIAGRA, PENIS ENLARGMENT, NIGERAIAN $$$100,000,000.00, FREE CREDIT REPORT, FREE 10 INCH PENIS ENLARGER, CLICK HERE FOR FREE VIAGRA WIN A FREE CAR!!! WORTH 10K$$$, NO CREDIT CHECK PAYDAY LOANS, CAR LOANS, INHERIT $10,675,981.98 US CURRENCY FROM NIGERIAN PRINCE US BANK ACCOUNT NEEDED</td>
</tr>
<tr>
<td><table width="520" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="5" style="border-bottom:solid 1px #2ecc71"> </td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td style="color:23cc71;"><table width="600" border="0" cellpadding="0" cellspacing="0" bgcolor="#2ecc71" style="color:23cc71;">
<tr>
<td bgcolor="#2ecc71" style=" color:#2ecc71;" align="center">
9 INCH PENIS, SPAM EMAIL, THIS IS SPAM, 10 INCH PENIS, VIAGRA, PENIS ENLARGMENT, NIGERAIAN $$$100,000,000.00, FREE CREDIT REPORT, FREE 10 INCH PENIS ENLARGER, CLICK HERE FOR FREE VIAGRA</td>
<td width="240" bgcolor="#2ecc71" style=" color:#2ecc71;" align="center"> WIN A FREE CAR!!! WORTH 10K$$$, NO CREDIT CHECK PAYDAY LOANS, CAR LOANS, INHERIT $10,675,981.98 US CURRENCY FROM NIGERIAN PRINCE US BANK ACCOUNT NEEDED</td>
<td width="40" bgcolor="#2ecc71" style=" color:#2ecc71;" align="center"> </td>
<td width="240" bgcolor="#2ecc71" style=" color:#2ecc71;" align="center"> </td>
<td width="40" bgcolor="#2ecc71" style=" color:#2ecc71;" align="center"> </td>
</tr>
<td width="40" bgcolor="#2ecc71" style=" color:#2ecc71;" align="center"> 9 INCH PENIS, SPAM EMAIL, THIS IS SPAM, 10 INCH PENIS, VIAGRA, PENIS ENLARGMENT, NIGERAIAN $$$100,000,000.00, FREE CREDIT REPORT, FREE 10 INCH PENIS ENLARGER, CLICK HERE FOR FREE VIAGRA</td>
<td width="240" bgcolor="#2ecc71" style=" color:#2ecc71;" align="center"> </td>
<td width="40" bgcolor="#2ecc71" style=" color:#2ecc71;" align="center"> </td>
<td width="240" bgcolor="#2ecc71" style=" color:#2ecc71;" align="center"> 9 INCH PENIS, SPAM EMAIL, THIS IS SPAM, 10 INCH PENIS, VIAGRA, PENIS ENLARGMENT, NIGERAIAN $$$100,000,000.00, FREE CREDIT REPORT, FREE 10 INCH PENIS ENLARGER, CLICK HERE FOR FREE VIAGRA</td>
<td width="40" bgcolor="#2ecc71" style=" color:#2ecc71;" align="center">
<!-- Spam Pixel Images -->
<img src="http://www.cdell.me/invite-site/green-pixel1.png" />
<img src="http://www.cdell.me/invite-site/green-pixel2.png" />
<img src="http://www.cdell.me/invite-site/green-pixel3.png" />
<img src="http://www.cdell.me/invite-site/green-pixel4.png" />
<img src="http://www.cdell.me/invite-site/green-pixel5.png" />
<img src="http://www.cdell.me/invite-site/green-pixel6.png" />
<img src="http://www.cdell.me/invite-site/green-pixel7.png" />
<img src="http://www.cdell.me/invite-site/green-pixel8.png" />
<img src="http://www.cdell.me/invite-site/green-pixel9.png" />
<img src="http://www.cdell.me/invite-site/green-pixel10.png" />
<img src="http://www.cdell.me/invite-site/green-pixel11.png" />
<img src="http://www.cdell.me/invite-site/green-pixel12.png" />
<img src="http://www.cdell.me/invite-site/green-pixel13.png" />
<img src="http://www.cdell.me/invite-site/green-pixel14.png" />
<img src="http://www.cdell.me/invite-site/green-pixel15.png" />
<img src="http://www.cdell.me/invite-site/green-pixel16.png" />
<img src="http://www.cdell.me/invite-site/green-pixel17.png" />
<img src="http://www.cdell.me/invite-site/green-pixel18.png" />
<img src="http://www.cdell.me/invite-site/green-pixel19.png" />
<img src="http://www.cdell.me/invite-site/green-pixel20.png" />
</td>
</tr>
</table></td>
</tr>
</table>
</body>';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html;" . "\r\n";
$headers .= "to:".$ro['emai_addrs']."\r\n";
$headers .= "from: ".$sender."\r\n";
mail($mail_to, $sub, $mail_body, $headers);
//echo $mail_body;
}
}
$var = "Invitation Sent Successfully";
}
Have you tried adding X-Spam related headers, so as to masquerade as something that went through and got caught by Spam Assassin?
If not, a few headers you might want to look into:
X-Spam-Score
X-Spam-Level
X-Spam-Status
X-Spam-Flag
X-Spam-Report
More info:
https://www.lamphost.com/Knowledge_Base/What_headers_are_added_to_emails_that_are_scanned_by_SpamAssassintm
There are plenty of things you can do to get it marked as spam, however, if someone has you listed as a 'safe-sender', 100% guarantees may be out of the question.
There are plenty of keywords you can use, they don't need to be shady words either. In the past, I've had issues just using large money amounts, exclamation points and the word 'free'.
Litmus is a great tool for checking your spam scores in different mail clients. For most spam software, it is an accumulative score, so you will easily be able to identify the worst (or in your case best) culprets.
Just BLACKLIST your Ip address,
also each blacklisting servers has their own listing criteria that may include technical listings, policy listings, and evidence based listings. Technical listings are those that occur mostly from mail server configuration issues such as missing or incorrect reverse DNS records, missing on incorrect banner greetings, and mail servers operating in IP address space that an ISP has specified that mail servers should not be operating in. Policy listings are those based on an operator that does not wish to receive email from certain countries, or ISPs, or has a history of no honoring unsubscribe requests. Evidence based listings are those where the operator has receive direct (or indirect) evidence that an IP address has been involved in sending unsolicited emails.

Copy HTML form in email PHP

I am trying to copy my HTML form in email body. Below is code where the form is already in php file but I want if the user submits html form file then all the form data between that is not hidden is copied (as disabled elements) in the body of the email. Also if there is any file attachment field, it should be attached to the email.
<?php
// multiple recipients
$to = 'demo#localhost.com' . ', '; // note the comma
$to .= 'demo#localhost.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body style="padding:3px; margin:0px;" bgcolor="#FFFFFF">
<table cellpadding="0" cellspacing="0" border="0" width="440">
<tr><td style="height:10px"></td></tr>
<tr>
<td colspan="2" style="text-align:justify; line-height:15px;" class="body">
<form name="frm" method="POST" action="careersuccess.php" enctype="multipart/form-data">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td width="23%" class="body"> Name</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="strname" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Address</td>
<td width="3%" class="body">:</td>
<td width="74%"><textarea cols="16" name="straddress"></textarea></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> City</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="strcity" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> State</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="strstate" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Contact No</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="strno" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Email</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="stremail" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Comments</td>
<td width="3%" class="body">:</td>
<td width="74%"><textarea cols="16" name="strcomments"></textarea></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Resume</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="file" name="strresume"></td>
</tr>
<tr><td style="height:10px"></td></tr>
<tr>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td colspan="2" align="center"> </td>
</tr>
</table>
</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 .= 'From: Birthday Reminder <birthday#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);
?>
I'll assume the form is submitted from a website, and that you're not trying to create a submittable form in an email. To copy the data submitted in the form, $_POST[""]; would surely be the best way to obtain the data. Obviously the data wouldn't be manipulatable once the email has arrived in the recipient's inbox but, as I say, I'm assuming you're not trying to create a form which can be submitted from an email.
Your form on the website was fine:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body style="padding:3px; margin:0px;" bgcolor="#FFFFFF">
<table cellpadding="0" cellspacing="0" border="0" width="440">
<tr><td style="height:10px"></td></tr>
<tr>
<td colspan="2" style="text-align:justify; line-height:15px;" class="body">
<form name="frm" method="POST" action="careersuccess.php" enctype="multipart/form-data">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td width="23%" class="body"> Name</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="strname" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Address</td>
<td width="3%" class="body">:</td>
<td width="74%"><textarea cols="16" name="straddress"></textarea></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> City</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="strcity" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> State</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="strstate" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Contact No</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="strno" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Email</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="stremail" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Comments</td>
<td width="3%" class="body">:</td>
<td width="74%"><textarea cols="16" name="strcomments"></textarea></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Resume</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="file" name="strresume"></td>
</tr>
<tr><td style="height:10px"></td></tr>
<tr>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td colspan="2" align="center"> </td>
</tr>
</table>
</body>
</html>
Your file careersuccess.php would then need to include something like:
<?php
// multiple recipients
$to = 'demo#localhost.com' . ', '; // note the comma
$to .= 'demo#localhost.com';
// subject
$subject = 'Birthday Reminders for August';
$strName = $_POST["strname"]; //assigns strname from form to PHP variable
$strAddress = $_POST["straddress"];
$strCity = $_POST["strcity"];
$strState = $_POST["strstate"];
$strNumber = $_POST["strnumber"];
$strEmail = $_POST["stremail"];
$strComments = $_POST["strcomments"];
$strResume = $_POST["strresume"];
$lineBreak = "<br />\n\"; //adds carriage return to break up your message
$message = "Name: ".$strName.$lineBreak."Address: ".$strAddress.$lineBreak."City: ".$strCity.$lineBreak."State: ".$strState.$lineBreak...for the rest of your variables;
// 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 .= 'From: Birthday Reminder <birthday#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);
?>
That will result in the submitted values of the form being copied in to the email in the $message variable for the mail() function.

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