PHP mail() with multipart/alternative

I was having issues with sending out HTML emails with PHP and getting the email trapped up in spam filters. I stumbled upon a great header add using multipart/alternative. Hope it helps someone!



$random = md5(time());
$mime_boundary = "==MULTIPART_BOUNDARY_$random";
$mime_boundary_header = chr(34) . $mime_boundary . chr(34);

...

$headers ...
$headers .= "Content-Type: multipart/alternative;\n" .
" boundary=" . $mime_boundary_header))

//@EXAMPLE
function mail_htmlnoattachment($mailto, $from_mail, $from_name, $replyto, $subject, $message) {

$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-Type: multipart/alternative;\n" .
" boundary=" . $mime_boundary_header)) ";
$header .= $message."\r\n\r\n";

if (mail($mailto, $subject, "", $header)) {
//echo "\n\rSending mail ... OK!\n\r"; // or use booleans here
} else {
//echo "\n\rSending mail ... ERROR!\n\r";
}
}

Voting for Attorneys General is Passe

Follow up to my genius-ery today. We should not vote for Attorney Generals. I find myself always leaving these blank on voting day They should be appointed for a limited terms of 6-8 years then we get a new one. No questions asked. Less corruption, less need for batman.

BTW, this is my first post on my new Tumblr digs with a custom URL. So long Drupal, I will miss you. So far so good!

Linux.com Interview

I recently sat down with Steve Burge at OpenSourceMatters to discuss how the Linux Foundation relaunched Linux.com using Joomla and how we scaled the application.

I serve as the Web Architect to the Linux Foundation, and help enable the Linux Foundation with websites and web technology that can help accomplish our strategic goals as an organization. I have been involved with full lifecycle development for large Consumer websites, to Enterprise Architecture for Federal and DoD. I am also an Entrepreneur, Strategist, Web Application Architect, Open Source Software evangelist, and a seasoned start-up veteran. I have been involved and continue to have interest in Web applications using Open Source technologies, and otherwise Open Source geekery…

Linux.com Screenshot

Read More…

Recent Project - Furnicology

Furnicology
www.furnicology.com

Furnicology was created to provide a marketplace for consumers and designers to discover beautiful, environmentally responsible products in addition to providing an outlet for sustainable education.

Work (Non-technical): User Experience, Brand Engagement, Community building, Ad operations
Work (Technical): Graphic Design, PHP5, MySQL 5, Joomla, Zend Framework, Flash, AJAX, Cloud Infrastructure, CDN

Recent Project - MuseAmp

MuseAmp, Inc.
www.museamp.com

MuseAmp.com is a social network that focuses on free networking for music industry professionals and fans, including profiles, blogs, and classifieds, and events.

Work (Non-technical): User Experience, Brand Engagement, Community building, Ad Operations
Work (Technical): Graphic Design, PHP5, MySQL 5, Joomla, Zend Framework, Flash, AJAX, Cloud Infrastructure, CDN

Product Management - From Lame to Got Game

The Anatomy of Product Evolution - Putfile.com

Putfile was a free file-hosting website started in January 2004 that provided video and photo hosting services. It was originally owned by Putfile Limited in the UK, and on February 6, 2007, it was purchased by ZVUE Corporation, an internet media company. As part of the strategy, ZVUE aimed to make Putfile media sharing more social and viral and capitalize on Putfile’s 5 million unique / month traffic.

Here is a set of screenshots that show the evolution of the site product offerings and design concepts I helped architect.

Version 1.0
Version 2.0
Version 3.0

Work (Non-technical): User Experience, Product Management, Ad operations
Work (Technical): Graphic Design, PHP5, MySQL 5, Zend Framework, Flash, AJAX, CDN

Recent Project - ZVUE Products

Zvueproducts.com product registration, and integration to SugarCRM platform.

Work (Technical): SugarCRM Integration and Development, UI design, PHP5, SOAP, Javascript

Screenshot:

ZVUE Products Screenshot

Recent Project - Hardball Report.com

Hardball Report
www.hardballreport.com

HarballReport.com provided comprehensive baseball news coverage and links to important baseball information. Complete baseball information including MLB, College Basketball scores and news.

Work (Non-technical): User Experience, Brand Engagement, Community building, Ad operations
Work (Technical): UI design, Identity, PHP5, MySQL 5, Mobile, Joomla, Social Widgets, SEO, and AJAX.

Screenshot

SugarCRM SOAP with PHP5 

This is a class that requires PHP5 with native SOAP library. SugarCRM has a conflict with PHP5 and NuSOAP (so dont use it) Dont use SOAP compression as SugarCRM has issue with this in v5.0

/**
* Register class
* 
* This class requires PHP5 with native SOAP library
* SugarCRM has a conflict with PHP5 and NuSOAP (so dont use it)
* Dont use SOAP compression as SugarCRM has issue with this in v5.0
* @example var_dump($sugar_client->__soapCall('get_entry', $get_entry_params));
* This will return a var dump of fields to grab or insert to
* 
*/
class Register {
public $errorNum = "";
public $errorMsg = "";
public function __construct(){
}
/**
* processForm function
* This function takes post data from index.php
* and will insert into db using SOAPClient (PHP5+ only)
*
* @param unknown_type $postdata
* @return result of error or successful soap insert
*/
public function processForm($postdata){
$combined_desc = "Model Number: ".$postdata['zvue_model']."\n--\n".
"Serial Number: ".$postdata['serial_number']."\n--\n".
"Purchase Date: ".$postdata['purchase_date']."\n--\n".
"Screen Rating: ".$postdata['screen']."\n--\n".
"Battery Life: ".$postdata['battery']."\n--\n".
"Sound Quality: ".$postdata['sound']."\n--\n".
"Appearance: ".$postdata['appearance']."\n--\n".
"Performance: ".$postdata['performance']."\n--\n".
"Gender: ".$postdata['gender']."\n--\n".
"How did you learn about our company: ".$postdata['learn_prod']."\n--\n".
"What do you like about your product: ".$postdata['like_prod']."\n--\n".
"What do you dislike about your product: ".$postdata['dislike_prod'];
// set up options array
$sugar_client = new SoapClient(null, array(        
'location' => 'https://crm.yourcompany.com/soap.php'
,'uri' => 'http://www.sugarcrm.com/sugarcrm'
,'soap_version'   => SOAP_1_1 //SOAP_1_2 - 1.2 not supported by sugar nusoap
,'trace' => 1
,'exceptions' => 0
// ,'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5
));  
//login to sugarcrm
$login_creds = array(
'user_auth' => array(
'user_name' => 'my_username',
'password' => md5('my_password'),
'version' => '.01'
),
'application_name' => 'companyproducts');
// grab valid session
$session_id = $sugar_client->__soapCall('login',$login_creds,NULL,NULL);
/*var_dump($session_id);
$get_entry_params = array(
'session' => $session_id->id,
'module_name' => 'Leads',  
'id'=>'7d0f25ae-11ab-4421-d67b-47fe9089da58'//lead
//'id'=>'db77961d-f77c-364a-9ac7-4803ee562add'//account
//'id'=>'4f8935c8-2342-f52e-cdd1-47fe9a766f14'//contact
);
var_dump($sugar_client->__soapCall('get_entry', $get_entry_params));
*/
$errorNo = $session_id->error;
if($errorNo->number == '0'){
$sess = $session_id->id;
$set_account_params = array(
'session' => $sess,
'module_name' => 'Accounts',
'name_value_list'=>array(
array('name'=>'name','value'=>$postdata['first_name'].' '.$postdata['last_name']),
array('name'=>'phone_office', 'value'=>$postdata['phone_work']),
array('name'=>'email1', 'value'=>$postdata['email_address']),
array('name'=>'billing_address_street', 'value'=>$postdata['address_l1'].' '.$postdata['apt_no']),
array('name'=>'billing_address_city', 'value'=>$postdata['city']),
array('name'=>'billing_address_state', 'value'=>$postdata['state']),
array('name'=>'billing_address_postalcode', 'value'=>$postdata['postal_code']),
array('name'=>'billing_address_country', 'value'=>$postdata['country_code']),
array('name'=>'company_account_type_c', 'value'=>'Users'),
array('name'=>'description','value'=> $combined_desc),
array('name'=>'team_id','value'=> 'b26781c7-20fa-7fb3-0df5-48350096ca40'),
array('name'=>'assigned_user_id', 'value'=>'f0bdcbe1-b7ea-d0b4-87f4-480fbb402142')
)
);
$insertAccount = $sugar_client->__soapCall('set_entry', $set_account_params);
$set_contact_params = array(
'session' => $sess,
'module_name' => 'Contacts',
'name_value_list'=>array(
array('name'=>'first_name','value'=>$postdata['first_name']),
array('name'=>'last_name','value'=>$postdata['last_name']),
array('name'=>'phone_work', 'value'=>$postdata['phone_work']),
array('name'=>'email1', 'value'=>$postdata['email_address']),
array('name'=>'primary_address_street', 'value'=>$postdata['address_l1'].' '.$_POST['apt_no']),
array('name'=>'primary_address_city', 'value'=>$postdata['city']),
array('name'=>'primary_address_state', 'value'=>$postdata['state']),
array('name'=>'primary_address_postalcode', 'value'=>$postdata['postal_code']),
array('name'=>'primary_address_country', 'value'=>$postdata['country_code']),
array('name'=>'company_account_type_c', 'value'=>'Users'),
array('name'=>'account_name','value'=>$postdata['first_name'].' '.$postdata['last_name']),
array('name'=>'account_id','value'=> $insertAccount->id),
array('name'=>'team_id','value'=> 'b26781c7-20fa-7fb3-0df5-48350096ca40'),
array('name'=>'assigned_user_id', 'value'=>'f0bdcbe1-b7ea-d0b4-87f4-480fbb402142')
)
);
$insertContact = $sugar_client->__soapCall('set_entry', $set_contact_params);
$set_lead_params = array(
'session' => $sess,
'module_name' => 'Leads',
'name_value_list'=>array(
array('name'=>'first_name','value'=>$postdata['first_name']),
array('name'=>'last_name','value'=>$postdata['last_name']),
array('name'=>'status', 'value'=>'Converted'),
array('name'=>'phone_work', 'value'=>$postdata['phone_work']),
array('name'=>'email1', 'value'=>$postdata['email_address']),
array('name'=>'primary_address_street', 'value'=>$_POST['address_l1'].' '.$postdata['apt_no']),
array('name'=>'primary_address_city', 'value'=>$postdata['city']),
array('name'=>'primary_address_state', 'value'=>$postdata['state']),
array('name'=>'primary_address_postalcode', 'value'=>$postdata['postal_code']),
array('name'=>'primary_address_country', 'value'=>$postdata['country_code']),
array('name'=>'converted', 'value'=> '1'),
array('name'=>'company_lead_type_c', 'value'=>'Users'),
array('name'=>'account_name','value'=>$postdata['first_name'].' '.$postdata['last_name']),
array('name'=>'lead_source','value'=>'Web Site'),
array('name'=>'description','value'=> $combined_desc),
array('name'=>'account_id','value'=> $insertAccount->id),
array('name'=>'contact_id','value'=> $insertContact->id),
array('name'=>'team_id','value'=> 'b26781c7-20fa-7fb3-0df5-48350096ca40'),
array('name'=>'assigned_user_id', 'value'=>'f0bdcbe1-b7ea-d0b4-87f4-480fbb402142')
)
);
$insertLead = $sugar_client->__soapCall('set_entry', $set_lead_params);
$this->errorNum = "0";
$this->errorMsg = "You have successfully registered your product. Enjoy!";
}
else{
$this->errorNum = "1";
$this->errorMsg = "Could not connect";
}
$result = array("errno" => $this->errorNum, "errmsg" => $this->errorMsg);
return $result;
}
}