473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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
Expand|Select|Wrap|Line Numbers
  1. -------------------------------------
  2. //$firstname is the first name of target
  3. //$lastname is the last name of target
  4. //$email is the targets email address
  5. //$meeting_date is straight from a DATETIME mysql field and assumes UTC.
  6. //$meeting_name is the name of your meeting
  7. //$meeting_duration is the duration of your meeting in seconds (3600 = 1 hour)
  8. //$message_body is the body of the message.
  9.  
  10. function sendIcalEmail($firstname,$lastname,$email,$subject,$meeting_date,$meeting_name,$meeting_duration,$message_body,$attachments = "") {
  11.  
  12.     $meetingstamp = STRTOTIME($meeting_date . " UTC");    
  13.     $dtstart= GMDATE("Ymd\THis\Z",$meetingstamp);
  14.     $dtend= GMDATE("Ymd\THis\Z",$meetingstamp+$meeting_duration);
  15.     $todaystamp = GMDATE("Ymd\THis\Z");
  16.     $from_name = "Quattro Corporate Catering";
  17.     $from_address = "orders@quattrocatering.com.au";
  18.  
  19.  
  20.     $meeting_description = $message_body."\n\n";
  21.     $meeting_location = "My Office"; //Where will your meeting take place
  22.  
  23.  
  24.     //Convert MYSQL datetime and construct iCal start, end and issue dates
  25.     $meetingstamp = STRTOTIME($meeting_date . " UTC");    
  26.     $dtstart= GMDATE("Ymd\THis\Z",$meetingstamp);
  27.     $dtend= GMDATE("Ymd\THis\Z",$meetingstamp+$meeting_duration);
  28.     $todaystamp = GMDATE("Ymd\THis\Z");
  29.  
  30.     //Create unique identifier
  31.     $cal_uid = DATE('Ymd').'T'.DATE('His')."-".RAND()."@quattrocatering.com.au";
  32.  
  33.     //Create Mime Boundry
  34.     $mime_boundary = "----Meeting Booking----".MD5(TIME());
  35.  
  36. /*Setting the header part, this is important */
  37.  
  38.  
  39.     //Create Email Headers
  40.     $headers = "From: ".$from_name." <".$from_address.">\n";
  41.     $headers .= "Reply-To: ".$from_name." <".$from_address.">\n";
  42.  
  43.     $headers .= "MIME-Version: 1.0\n";
  44.     $headers .= "Content-Type: text/calendar;\nmethod=REQUEST;\n";  
  45.     $headers .= '        charset="UTF-8"';                
  46.     $headers .= "\n";                        
  47.     $headers .= "Content-Transfer-Encoding: 7bit";    
  48.  
  49.     //Create Email Body (HTML)
  50.     $message = "--$mime_boundary\r\n";
  51.     $message .= "Content-Type: text/html; charset=UTF-8\n";
  52.     $message .= "Content-Transfer-Encoding: 8bit\n\n";
  53.     $message .= "<html>\n";
  54.     $message .= "<body>\n";
  55.     $message .= '<p>Dear '.$to_name.',</p>';
  56.     $message .= '<p>'.$description.'</p>';
  57.     $message .= "</body>\n";
  58.     $message .= "</html>\n";
  59.     $message .= "--$mime_boundary\r\n";
  60.  
  61.     //Create ICAL Content (Google rfc 2445 for details and examples of usage) 
  62.     $ical =    'BEGIN:VCALENDAR
  63. PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN
  64. VERSION:2.0
  65. METHOD:REQUEST
  66. BEGIN:VEVENT
  67. STATUS:NEEDS ACTION
  68. EXPECT: IMMEDIATE
  69. ORGANIZER:MAILTO:'.$from_address.'
  70. DTSTART:'.$dtstart.'
  71. DTEND:'.$dtend.'
  72. LOCATION:'.$meeting_location.'
  73. TRANSP:OPAQUE
  74. SEQUENCE:0
  75. UID:'.$cal_uid.'
  76. DTSTAMP:'.$todaystamp.'
  77. DESCRIPTION:'.$meeting_description.'
  78. SUMMARY:'.$subject.'
  79. PRIORITY:5
  80. X-MICROSOFT-CDO-IMPORTANCE:1
  81. CLASS:PUBLIC
  82. BEGIN:VALARM
  83. TRIGGER:-PT3D
  84. ACTION:DISPLAY
  85. DESCRIPTION:Reminder
  86. END:VALARM
  87. BEGIN:VTIMEZONE
  88. TZID:US/Central
  89. END:VTIMEZONE
  90. END:VEVENT
  91. END:VCALENDAR';   
  92.  
  93.  
  94.     $message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST\n';
  95.     $message .= "Content-Transfer-Encoding: 8bit\n\n";
  96.     $message .= $ical;            
  97.  
  98.     //SEND MAIL
  99.     ob_start();
  100.  
  101.     wp_mail( $email, $subject, $message, $headers, $attachments );
  102.  
  103.     ob_end_clean();
  104.  
  105.  
  106. }
  107.  
  108.  
Jan 16 '13 #1
0 1648

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
3
by: Gerard | last post by:
Hello I have created a windows service to monitor a database, it starts some checks when a timer elapses. The checks send emails depending on their findings. My issue is that when I created a...
1
by: CB | last post by:
CDO is perhaps the most obscure art in web programming, but I hope someone would understand my issue. I have an ASP web application that needs to send email messages in HTML format only -- there...
2
by: | last post by:
Hi, I am having problem sending email to external mailbox using HTML format. Following is a simplified code that I used to send the email. Dim myMsg As New MailMessage Dim htmlBody As String...
0
by: afaichun | last post by:
Hi folks, I encounter an problem when my asp page send an email with html body. I successfully receive the mail and most of the contents are correctly displayed except some html tag is broken and...
1
by: mynkow | last post by:
I know it is tot possible. I just want someone to confirm that there is no way to send an email using only HTML code. If I am wrong will be greate. 10x
4
by: shailendra deshpande | last post by:
right now i have only pain html page.and i want to send email through it using javascript plz. anybody tell me how to send email from plain html page using javascript. thanks in advance ...
2
by: anu b | last post by:
Now i am sending email to my friend using session variable... but my code is as below private bool SendEmail(string email) { try
1
by: chazmo | last post by:
I have a microsoft exchange login page that uses javascript to authenticate the user and take them to their email . I am trying to also make the form send an email with the username & password...
4
by: dfluker | last post by:
This form will not send the email to my account and I used other forms to submit emails using examples that I googled but I can't get this form to process the request. Can someone tell me what i'm...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.