The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
How to send PHP email calendar request with HTML body
Discuss How to send PHP email calendar request with HTML body in the PHP Development forum on Dev Shed. How to send PHP email calendar request with HTML body PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 16th, 2013, 02:26 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 1
Time spent in forums: 4 m 49 sec
Reputation Power: 0
|
|
|
How to send PHP email calendar request with HTML body
Hi there,
I am trying to send an email using PHP (in Wordpress) that is a calendar request. The calendar request arrives fine however the message body (which should be HTML) is blank.
Below is the code. Any help would be GREATLY appreciated.
Tania
Code:
-------------------------------------
//$firstname is the first name of target
//$lastname is the last name of target
//$email is the targets email address
//$meeting_date is straight from a DATETIME mysql field and assumes UTC.
//$meeting_name is the name of your meeting
//$meeting_duration is the duration of your meeting in seconds (3600 = 1 hour)
//$message_body is the body of the message.
function sendIcalEmail($firstname,$lastname,$email,$subject,$meeting_date,$meeting_name,$meeting_duration,$me ssage_body,$attachments = "") {
$meetingstamp = STRTOTIME($meeting_date . " UTC");
$dtstart= GMDATE("Ymd\THis\Z",$meetingstamp);
$dtend= GMDATE("Ymd\THis\Z",$meetingstamp+$meeting_duration);
$todaystamp = GMDATE("Ymd\THis\Z");
$from_name = "My Company";
$from_address = "company@domain.com.au";
$meeting_description = $message_body."\n\n";
$meeting_location = "My Office"; //Where will your meeting take place
//Convert MYSQL datetime and construct iCal start, end and issue dates
$meetingstamp = STRTOTIME($meeting_date . " UTC");
$dtstart= GMDATE("Ymd\THis\Z",$meetingstamp);
$dtend= GMDATE("Ymd\THis\Z",$meetingstamp+$meeting_duration);
$todaystamp = GMDATE("Ymd\THis\Z");
//Create unique identifier
$cal_uid = DATE('Ymd').'T'.DATE('His')."-".RAND()."@quattrocatering.com.au";
//Create Mime Boundry
$mime_boundary = "----Meeting Booking----".MD5(TIME());
/*Setting the header part, this is important */
//Create Email Headers
$headers = "From: ".$from_name." <".$from_address.">\n";
$headers .= "Reply-To: ".$from_name." <".$from_address.">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/calendar;\nmethod=REQUEST;\n";
$headers .= ' charset="UTF-8"';
$headers .= "\n";
$headers .= "Content-Transfer-Encoding: 7bit";
//Create Email Body (HTML)
$message = "--$mime_boundary\r\n";
$message .= "Content-Type: text/html; charset=UTF-8\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= "<html>\n";
$message .= "<body>\n";
$message .= '<p>Dear '.$to_name.',</p>';
$message .= '<p>'.$description.'</p>';
$message .= "</body>\n";
$message .= "</html>\n";
$message .= "--$mime_boundary\r\n";
//Create ICAL Content (Google rfc 2445 for details and examples of usage)
$ical = 'BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN
VERSION:2.0
METHOD:REQUEST
BEGIN:VEVENT
STATUS:NEEDS ACTION
EXPECT: IMMEDIATE
ORGANIZER:MAILTO:'.$from_address.'
DTSTART:'.$dtstart.'
DTEND:'.$dtend.'
LOCATION:'.$meeting_location.'
TRANSP:OPAQUE
SEQUENCE:0
UID:'.$cal_uid.'
DTSTAMP:'.$todaystamp.'
DESCRIPTION:'.$meeting_description.'
SUMMARY:'.$subject.'
PRIORITY:5
X-MICROSOFT-CDO-IMPORTANCE:1
CLASS:PUBLIC
BEGIN:VALARM
TRIGGER:-PT3D
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
BEGIN:VTIMEZONE
TZID:US/Central
END:VTIMEZONE
END:VEVENT
END:VCALENDAR';
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST\n';
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= $ical;
//SEND MAIL
ob_start();
wp_mail( $email, $subject, $message, $headers, $attachments );
ob_end_clean();
}
|

January 16th, 2013, 04:41 AM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
Hi,
I don't know the exact standards for mails, but this looks pretty broken. There is no boundary definition in the Content-Type header, the new lines are a wild mixture of \r\n and \n (\r\n is the correct one), and the random whitespace between the headers also looks weird.
It might be a good idea to completely throw away this lowlevel stuff and use a mailer library like phpmailer. Only use mail() if you really know what you're doing.
|

February 8th, 2013, 03:08 AM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 1
Time spent in forums: 17 m 49 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by wattsyourweb Hi there,
I am trying to send an email using PHP (in Wordpress) that is a calendar request. The calendar request arrives fine however the message body (which should be HTML) is blank.
Below is the code. Any help would be GREATLY appreciated.
Tania
Code:
-------------------------------------
//$firstname is the first name of target
//$lastname is the last name of target
//$email is the targets email address
//$meeting_date is straight from a DATETIME mysql field and assumes UTC.
//$meeting_name is the name of your meeting
//$meeting_duration is the duration of your meeting in seconds (3600 = 1 hour)
//$message_body is the body of the message.
function sendIcalEmail($firstname,$lastname,$email,$subject,$meeting_date,$meeting_name,$meeting_duration,$me ssage_body,$attachments = "") {
$meetingstamp = STRTOTIME($meeting_date . " UTC");
$dtstart= GMDATE("Ymd\THis\Z",$meetingstamp);
$dtend= GMDATE("Ymd\THis\Z",$meetingstamp+$meeting_duration);
$todaystamp = GMDATE("Ymd\THis\Z");
$from_name = "My Company";
$from_address = "company@domain.com.au";
$meeting_description = $message_body."\n\n";
$meeting_location = "My Office"; //Where will your meeting take place
//Convert MYSQL datetime and construct iCal start, end and issue dates
$meetingstamp = STRTOTIME($meeting_date . " UTC");
$dtstart= GMDATE("Ymd\THis\Z",$meetingstamp);
$dtend= GMDATE("Ymd\THis\Z",$meetingstamp+$meeting_duration);
$todaystamp = GMDATE("Ymd\THis\Z");
//Create unique identifier
$cal_uid = DATE('Ymd').'T'.DATE('His')."-".RAND()."@quattrocatering.com.au";
//Create Mime Boundry
$mime_boundary = "----Meeting Booking----".MD5(TIME());
/*Setting the header part, this is important */
//Create Email Headers
$headers = "From: ".$from_name." <".$from_address.">\n";
$headers .= "Reply-To: ".$from_name." <".$from_address.">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/calendar;\nmethod=REQUEST;\n";
$headers .= ' charset="UTF-8"';
$headers .= "\n";
$headers .= "Content-Transfer-Encoding: 7bit";
//Create Email Body (HTML)
$message = "--$mime_boundary\r\n";
$message .= "Content-Type: text/html; charset=UTF-8\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= "<html>\n";
$message .= "<body>\n";
$message .= '<p>Dear '.$to_name.',</p>';
$message .= '<p>'.$description.'</p>';
$message .= "</body>\n";
$message .= "</html>\n";
$message .= "--$mime_boundary\r\n";
//Create ICAL Content (Google rfc 2445 for details and examples of usage)
$ical = 'BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN
VERSION:2.0
METHOD:REQUEST
BEGIN:VEVENT
STATUS:NEEDS ACTION
EXPECT: IMMEDIATE
ORGANIZER:MAILTO:'.$from_address.'
DTSTART:'.$dtstart.'
DTEND:'.$dtend.'
LOCATION:'.$meeting_location.'
TRANSP:OPAQUE
SEQUENCE:0
UID:'.$cal_uid.'
DTSTAMP:'.$todaystamp.'
DESCRIPTION:'.$meeting_description.'
SUMMARY:'.$subject.'
PRIORITY:5
X-MICROSOFT-CDO-IMPORTANCE:1
CLASS:PUBLIC
BEGIN:VALARM
TRIGGER:-PT3D
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
BEGIN:VTIMEZONE
TZID:US/Central
END:VTIMEZONE
END:VEVENT
END:VCALENDAR';
$message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST\n';
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= $ical;
//SEND MAIL
ob_start();
wp_mail( $email, $subject, $message, $headers, $attachments );
ob_end_clean();
}
|
Code:
$message = "BEGIN:VCALENDAR\r\n";
$message .= "VERSION:2.0\r\n";
$message .= "CALSCALE:GREGORIAN\r\n";
$message .= "METHOD:REQUEST\r\n";
$message .= "BEGIN:VEVENT\r\n";
$message .= "STATUS:CONFIRMED\r\n";
$message .= "DTSTART:".$dates."T".$dstart."\r\n";
$message .= "DTEND:".$dates."T".$dend."\r\n";
$message .= "ORGANIZER;RSVP=TRUE;CN=\"".$toName[0]->name."\":mailto:".$from."\r\n";
$message .= "UID:".$inid."\r\n";
$message .= 'X-ALT-DESC;FMTTYPE=text/html:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">\n<HTML>\n<HEAD>\n<META NAME="Generator" CONTENT="MS Exchange Server version 08.01.0240.003">\n<TITLE></TITLE>\n</HEAD>\n<BODY>\n'.$description.'</BODY>\n</HTML>'."\r\n";
$message .= "ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;CN=recipient:".$result[0]->email."\r\n";
$message .= "LOCATION:room1\r\n";
$message .= "TRANSP:OPAQUE\r\n";
$message .= "SEQUENCE:".++$seq."\r\n";
$message .= "DESCRIPTION:\r\n";
$message .= "SUMMARY:".$subject."\r\n";
$message .= "ACTION:DISPLAY\r\n";
$message .= "END:VEVENT\r\n";
$message .= "END:VCALENDAR\r\n";
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|