PHP Email On iPhone Not Displaying Correctly - php

I have a form that sends an email to the website owner and the form submitter. It looks great everywhere but on an iPhone it includes all of the html code.
Here is my code to process the form:
<?php
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$link = $_POST['link'];
$to = 'me#me.com';
$toCust = $email_field;
$subject = 'Lead From Website';
$random_hash = md5(date('r', time()));
$headers = "From: me#me.com\r\nReply-To: $email; ";
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
ob_start();
?>
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: 7bit
<h3>Contact Form Submission From Website</h3>
<table width="39%" cellpadding="10" border="0">
<tr>
<td width="47%"><strong>Name:</strong></td>
<td width="53%" style='color:#990000'><?php echo $name_field; ?></td>
</tr>
<tr>
<td><strong>Email:</strong></td>
<td style='color:#990000'><?php echo $email_field; ?></td>
</tr>
<tr>
<td><strong>Phone Number:</strong></td>
<td style='color:#990000'><?php echo $phone; ?></td>
</tr>
<tr>
<td><strong>Message:</strong></td>
<td style='color:#990000'><?php echo $message; ?></td>
</tr>
</table>
--PHP-alt-<?php echo $random_hash; ?>--
<?
$message = ob_get_clean();
if(isset($_POST['link']) && $_POST['link'] == ''){
$mail_sent = #mail( $to, $subject, $message, $headers );
$mail_sent = #mail( $toCust, $subject, $message, $headers );
header('Location: thankyou.html');
}
echo $mail_sent ? "Your email has been sent." : "The message failed to send. Our form thinks you're spam. If you're not, please give us a call";
?>
and here is was I get on my iPhone as plain text:
--PHP-alt-1962a6e1cb0d62a23c8e1743bd157401
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: 7bit
<html>
<body>
<h3>Contact Form Submission From Website</h3>
<table width="39%" cellpadding="10" border="0">
<tr>
<td width="47%"><strong>Name:</strong></td>
<td width="53%" style='color:#990000'>Dave</td>
</tr>
<tr>
<td><strong>Email:</strong></td>
<td style='color:#990000'>me#me.com</td>
</tr>
<tr>
<td><strong>Phone Number:</strong></td>
<td style='color:#990000'>666-666-6666</td>
</tr>
<tr>
<td><strong>Message:</strong></td>
<td style='color:#990000'>test of iphone</td>
</tr>
</table>
</body>
</html>
--PHP-alt-1962a6e1cb0d62a23c8e1743bd157401--

You problem is likely here:
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: 7bit
UTF-8 and 7bit encodings are pretty much mutually exclusive seeing as UTF-8 is a multibyte encoding. You should probably switch to quoted-printable and use quoted_printable_encode(). There are drop-in replacements in the comments if you're using PHP < 5.3.
edit
$part_header = <<<_EOI_
--PHP-alt-$random_hash
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
_EOI_;
$part_body = <<<_EOI_
<html>
<body>
<h3>Contact Form Submission From Website</h3>
<table width="39%" cellpadding="10" border="0">
<tr>
<td width="47%"><strong>Name:</strong></td>
<td width="53%" style='color:#990000'>$name_field</td>
</tr>
<tr>
<td><strong>Email:</strong></td>
<td style='color:#990000'>$email_field</td>
</tr>
<tr>
<td><strong>Phone Number:</strong></td>
<td style='color:#990000'>$phone</td>
</tr>
<tr>
<td><strong>Message:</strong></td>
<td style='color:#990000'>$message</td>
</tr>
</table>
</body>
</html>
--PHP-alt-$random_hash--
_EOI_;
$message = $part_header . quoted_printable_encode($part_body);

Related

file_get_contents in php is not returning E-mail id, why?

Actually I am sending email from php. When I am using file_get_contents() for email body from external file, its not returning email id. Instead email id it's returning '[email protected]'.
Here is my code to call the file with file_get_contents():
$params = 'for=team&name='.urlencode($name).'&email='.urlencode($email).'&phone='.urlencode($phone).'&company='.urlencode($company).'&looking_for='.$looking_for.'&country='.urlencode($country).'&source_page='.urlencode($source_page);
$team_msg = file_get_contents(get_template_directory_uri().'/mail-template/contact_us_email_temp.php?'.$params);
$headers[] = "MIME-Version: 1.0" . "\r\n";
$headers[] .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers[] .= 'From: Someone <someone#domainname.com>';
$to = 'myselft#domainname.com';
$team_subject = 'email subject';
wp_mail($to, $team_subject, $team_msg, $headers );
And Here is the 'contact_us_email_temp.php' which is called from function:
$message = "<table border='0'><tbody>
<tr><td colspan='2'>Users Detail:</td></tr>
<tr>
<td><b>Name</b></td>
<td>".$_GET['name']."</td>
</tr>
<tr>
<td><b>Official Email</b></td>
<td>".$_GET['email']."</td>
</tr>
<tr>
<td><b>Company</b></td>
<td>".$_GET['company']."</td>
</tr>
<tr>
<td><b>Mobile Number</b></td>
<td>".$_GET['phone']."</td>
</tr>
<tr>
<td><b>Looking For</b></td>
<td>".$_GET['looking_for']."</td>
</tr>
<tr>
<td><b>Country</b></td>
<td>".$_GET['country']."</td>
</tr>
<tr>
<td><b>Source Page</b></td>
<td>".$_GET['source_page']."</td></tr>
<tr>
</tbody>
</table>";
echo $message;
I am not sure what's wrong with the function.
Thanks
file_get_contents() doesn't work like a HTTP Request. You're loading a the ACTUAL file as a string and any code isn't executed. So when you send the mail now, the viewer will see the $_GET['name'] for example. What you want to do is create a function out of the contact_us_email_temp.php file and use the GET parameters as function parameters.
function getEmail($name, $email, $company, $phone, $looking_for, $country, $source_page) {
$message = "
<table border='0'><tbody>
<tr><td colspan='2'>Users Detail:</td></tr>
<tr>
<td><b>Name</b></td>
<td>".$name."</td>
</tr>
<tr>
<td><b>Official Email</b></td>
<td>".$email."</td>
</tr>
<tr>
<td><b>Company</b></td>
<td>".$company."</td>
</tr>
<tr>
<td><b>Mobile Number</b></td>
<td>".$phone."</td>
</tr>
<tr>
<td><b>Looking For</b></td>
<td>".$looking_for."</td>
</tr>
<tr>
<td><b>Country</b></td>
<td>".$country."</td>
</tr>
<tr>
<td><b>Source Page</b></td>
<td>".$source_page."</td></tr>
<tr>
</tbody>
</table>";
return $message;
}
Require this script in your main script and run the function instead of file_get_contents

PHP Mail not showing HTML in Switch Statement

I have a form with all the submissions going to one person but also sends a copy to another person responsible for the State that the user chose with the switch statement. The notification email that goes the the main admin looks fine (html is generated) but the ones in the switch statement are showing as plain text and show the HTML tags. Any idea how to fix this? Thank you.
//after user registers send notification to admin
$to = 'admin#email.com'
$subject = 'subject';
$message = "<!DOCTYPE html>
<html>
<body>
<div align='left'>
<strong>New Registration Information:</strong><br />
<br />
<table cellspacing=\"4\" cellpadding=\"4\" align=\"left\">
<tr>
<td><strong>Username:</strong></td>
<td>".$userInput."</td>
</tr>
<tr>
<td><strong>Password:</strong></td>
<td>".$passInput."</td>
</tr>
<tr>
<td><strong>Email:</strong></td>
<td>".$emailInput."</td>
</tr>
<tr>
<td><strong>First Name:</strong></td>
<td> ".$fnameInput."</td>
</tr>
<tr>
<td><strong>Middle Name:</strong></td>
<td>".$mnameInput."</td>
</tr>
<tr>
<td><strong>Last Name:</strong></td>
<td>".$lnameInput."</td>
</tr>
<tr>
<td><strong>Job Title:</strong></td>
<td>".$jobtitleInput."</td>
</tr>
<tr>
<td><strong>Company</strong></td>
<td>".$companyInput."</td>
</tr>
<tr>
<td><strong>Address:</strong></td>
<td>".$addressInput."</td>
</tr>
<tr>
<td><strong>City:</strong></td>
<td>".$cityInput."</td>
</tr>
<tr>
<td><strong>State:</strong></td>
<td>".$stateInput."</td>
</tr>
<tr>
<td><strong>Zip:</strong></td>
<td>".$zipInput."</td>
</tr>
<tr>
<td><strong>Phone Number:</strong></td>
<td>".$phoneInput."</td>
</tr>
<tr>
<td><strong>Registered State:</strong></td>
<td>".$registeredstateInput."</td>
</tr>
<tr>
<td><strong>Membership Level:</strong></td><td>";
if($membershipLevel == 1)
$message .= "Level 1 Here</td></tr></table></div></html>";
else if($membershipLevel == 2)
$message .= "Level 2 Here</td></tr></div></html>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);
//now send email to State contact
switch($registeredstateInput){
case "AZ":
$to = 'emailaddress1#email.com';
break;
case "AR":
$to = 'emailaddress2#email.com';
break;
case "CA":
$to = 'emailaddress3#email.com';
break;
}
//if that state doesn't have a contact, don't send email
if($to != 'admin#email.com')
{
mail($to, $subject, $message);
}

Receiving email from contact form

I was working on a simple contact form and after submit button is click it redirects to the thank you page which worked perfectly and received the email from the form. Right now, somehow it doesnt send email anymore. I dont know what I did that messed up the code.
PHP
<?php
$toemail = "cluneborg#hotmail.com";
$subject = "New Agent Inquries";
$full_name = $_POST['full_name'];
$email = $_POST['email'];
$agent_type = $_POST['agent_type'];
if($_SERVER['REQUEST_METHOD']=="POST") {
$full_name=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['full_name']));
$email=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['email']));
$agent_type=str_replace ( array("\n"), array(" <br>"),trim($_REQUEST['agent_type']));
$contentmsg=stripslashes("<br><b><font style=color:#CC3300>$subject</font></b><br>
<table width=708 border=0 cellpadding=2 cellspacing=1 bgcolor=#CCCCCC>
<tr>
<td width=165 align=right valign=top bgcolor=#FFFFFF><B>Full Name: </b> </td>
<td width=565 align=left valign=top bgcolor=#FFFFFF> $full_name</td>
</tr>
<tr>
<td width=165 align=right valign=top bgcolor=#FFFFFF><B>Email Address: </b> </td>
<td width=565 align=left valign=top bgcolor=#FFFFFF> $email</td>
</tr>
<tr>
<td width=165 align=right valign=top bgcolor=#FFFFFF><B>Type of Agent:</b> </td>
<td width=565 align=left valign=top bgcolor=#FFFFFF> $agent_type</td>
</tr>
</table>
");
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= 'To: Mary <mary#example.com>, Eric <eric#example.com>' . "\r\n";
$headers .= 'From: Website' . "\r\n";
if(mail($toemail,$subject,$contentmsg,$headers)){
header("Location: http://www.magnixsolutions.com/clients/tas/thanks.html");
}else{
echo "Mail was not sent!";
}
}
?>

PHP MAILER, HOW TO INSERT HTML TABLE

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>";

Text direction and alignment in email sent via email() using PHP

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.

Categories