PHP mail html/plain issue on Mac

I have some code which sends an email via php.
It works great on all systems and software except for Mac Mail.

The code is here (I’ve left it all in but I am sure this is just a problem with the php headers?)

[php]<?php
if(!class_exists(‘QuoteCalc’))
{
class QuoteCalc
{
function __construct()
{
global $wpdb;
$this->db = $wpdb;
$this->calculate();

$this->form = $_POST['qf_form'];
$this->quantity = $_POST['quantity'];
$this->media = $_POST['field_field_media'];
$this->printing = $_POST['field_field_print'];
$this->packaging = $_POST['field_field_pack'];
/* get subfields (inlay and paper inserts)*/
$this->sub_pack_fields = array();
foreach($_POST as $key => $val)
{
	if($val != 0 and substr($key, 0, 14) == 'sub_pack_field')
	{
		$this->sub_pack_fields[] = $val;
	}
}

$this->quote = $this->calculate();

if($this->quote_mail())
	$this->save_quote_to_db();

}

function calculate()
{
$priceObj = new Prices($this->form);
$media_price = $priceObj->get_media_price_by_media_id($this->media);
$print_price = $priceObj->get_print_price_by_print_id($this->printing);
$pack_price = $priceObj->get_pack_price($this->packaging, (int)$this->sub_pack_fields[0], (int)$this->sub_pack_fields[1]);

$base_price = $pack_price + $print_price + $media_price;

$quote = $priceObj->prices_by_quantity($this->quantity, $base_price);
return $quote;

}

function quote_mail()
{
$send_to = $_POST[‘qf_email’];
if($this->check_email($send_to))
{
$fieldObj = new Field();
$media_title = $fieldObj->get_value_by_id($this->media);
$print_title = $fieldObj->get_value_by_id($this->printing);
$pack_title = $fieldObj->get_value_by_id($this->packaging);
$sub_1_title = $fieldObj->get_value_by_id($this->sub_pack_fields[0]);
$sub_2_title = $fieldObj->get_value_by_id($this->sub_pack_fields[1]);

//define the subject of the email
$subject = 'Quote from '.get_bloginfo(‘name’);
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date(‘r’, time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = “From: [email protected]” . “\n”.
“MIME-Version: 1.0” . “\n”.
“Content-Type: multipart/alternative; boundary=“PHP-alt-”.$random_hash.”"".
“Content-Transfer-Encoding: 7bit”. “\r\n”;

//define the body of the message.
ob_start(); //Turn on output buffering
?>
–PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset=“iso-8859-1”
Content-Transfer-Encoding: 7bit

Quantity: <?php echo $this->quantity ?> \n
Media: <?php echo $media_title ?>\n
Print: <?php echo $print_title ?>\n
Packaging: <?php echo $pack_title ?>\n

<?php 
if($sub_1_title)
	echo " with ".$sub_1_title; 
	
if($sub_2_title)
	echo " with ".$sub_2_title;
?>

Quote Price: <?php echo $this->quote; ?>

–PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset=“iso-8859-1”
Content-Transfer-Encoding: 7bit

<table width="620" border="0" align="center" cellpadding="0" cellspacing="0" style="width:620px !important; margin:auto !important;">
  <tr>
	<td>content goes here</td>
  </tr>
</table>

–PHP-alt-<?php echo $random_hash; ?>–

<? //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email $mail_sent = @mail( $send_to, $subject, $message, $headers ); return $mail_sent; } else return false; } function save_quote_to_db() { $pack = $this->packaging; if($this->sub_pack_fields[0]) $pack .= ", ".$this->sub_pack_fields[0]; if($this->sub_pack_fields[1]) $pack .= ", ".$this->sub_pack_fields[1]; $q = "INSERT INTO ".$this->db->prefix."quotes SET quote=".$this->quote.", form=".$_POST['qf_form'].", quantity=".$this->quantity.", media='".$this->media."', print='".$this->printing."', pack='".$pack."', username='".$_POST['qf_username']."', email='".$_POST['qf_email']."', company='".$_POST['qf_company']."', contact_number='".$_POST['qf_contact_number']."', additional_info='".$_POST['qf_additional_info']."', time='".time()."'"; return $this->db->query($this->db->prepare($q)); } function check_email($email) { preg_match("/^[a-zA-Z0-9\._-]*@[a-zA-Z0-9\._-]*$/" , $email, $m); if (empty($m)) return false; else return true; } } } ?>[/php]

It renders as html in all email applications, but on Mac Mail, I get both versions like this…

–PHP-alt-778170234d7c4efa11fa8fb643e8c5f8
Content-Type: text/plain; charset=“iso-8859-1”
Content-Transfer-Encoding: 7bit

Quantity: 10 \n
Media: CD\n
Print: Black & White\n
Packaging: Paper Sleeve with Window\n

Quote Price: 46.00
–PHP-alt-778170234d7c4efa11fa8fb643e8c5f8
Content-Type: text/html; charset=“iso-8859-1”
Content-Transfer-Encoding: 7bit

<table width="620" border="0" align="center" cellpadding="0" cellspacing="0" style="width:620px !important; margin:auto !important;">

content goes here

–PHP-alt-778170234d7c4efa11fa8fb643e8c5f8–

Sponsor our Newsletter | Privacy Policy | Terms of Service