通过PHP CURL发送事件日历通知邮件(Event Calender Notification Mail through PHP CURL)

编程入门 行业动态 更新时间:2024-10-27 18:26:04
通过PHP CURL发送事件日历通知邮件(Event Calender Notification Mail through PHP CURL)

我正在尝试将事件日历发送到gmail / yahoo / outlook。 为此,我正在使用

$from_name = "My Name"; $from_address = "xxxxxx@example.com"; $subject = "Meeting Booking"; //Doubles as email subject and meeting subject in calendar $meeting_description = "Here is a brief description of my meeting\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()."@mydomain.com"; //Create Mime Boundry $mime_boundary = "----Meeting Booking----".md5(time()); //Create Email Headers $headers = array( 'From:'.$from_name.' <'.$from_address.'>\n', 'Reply-To: '.$from_name.' <'.$from_address.'>\n', 'MIME-Version: 1.0\n', 'Content-Type: multipart/alternative; boundary='.$mime_boundary.'\n', 'Content-class: urn:content-classes:calendarmessage\n' ); // $headers = "From: ".$from_name." <".$from_address.">\n"; // $headers .= "Reply-To: ".$from_name." <".$from_address.">\n"; // // $headers .= "MIME-Version: 1.0\n"; // $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n"; // $headers .= "Content-class: urn:content-classes:calendarmessage\n"; //Create Email Body (HTML) $message .= "--$mime_boundary\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 '.$firstname.' '.$lastname.',</p>'; $message .= '<p>Here is my HTML Email / Used for Meeting Description</p>'; $message .= "</body>\n"; $message .= "</html>\n"; $message .= "--$mime_boundary\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:PUBLISH BEGIN:VEVENT 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 CLASS:PUBLIC END:VEVENT END:VCALENDAR'; $message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST;charset=utf-8\n'; $message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST\n'; $message .= "Content-Transfer-Encoding: 8bit\n\n"; $message .= $ical; $mail_vars = array( 'from_name' => $from_name, 'from' => $from_address, 'to' => $email, 'subject' => $subject, 'headers' => $headers, 'body' => $message, ); echo "<pre>"; //print_r($mail_vars); echo "</pre>";

注意:如果我通过简单的mail()函数发送它,我在这里没有提到mail()函数,它工作正常。 但是,如果我使用CURL发送相同的邮件,我没有获得.ics文件附件,并且邮件没有格式化。 简单地说,邮件看起来像这样

这是CURL代码

first way : $ch = curl_init($posturl); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS,$vars); curl_setopt($ch, CURLOPT_HEADER,0); // DO NOT RETURN HTTP HEADERS curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE CONTENTS OF THE CALL $Rec_Data = curl_exec($ch); second way : $ch = curl_init($posturl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $mailparams['headers']); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $userpwd); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_POSTFIELDS, $body); $Rec_Data = curl_exec($ch);

如果我使用第一种方式,我可以发送邮件,但没有格式化。 在第二种方式,邮件不会。

请检查并让我知道。 提前致谢!

I am trying to send the event calender to gmail/yahoo/outlook. For this i am using

$from_name = "My Name"; $from_address = "xxxxxx@example.com"; $subject = "Meeting Booking"; //Doubles as email subject and meeting subject in calendar $meeting_description = "Here is a brief description of my meeting\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()."@mydomain.com"; //Create Mime Boundry $mime_boundary = "----Meeting Booking----".md5(time()); //Create Email Headers $headers = array( 'From:'.$from_name.' <'.$from_address.'>\n', 'Reply-To: '.$from_name.' <'.$from_address.'>\n', 'MIME-Version: 1.0\n', 'Content-Type: multipart/alternative; boundary='.$mime_boundary.'\n', 'Content-class: urn:content-classes:calendarmessage\n' ); // $headers = "From: ".$from_name." <".$from_address.">\n"; // $headers .= "Reply-To: ".$from_name." <".$from_address.">\n"; // // $headers .= "MIME-Version: 1.0\n"; // $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n"; // $headers .= "Content-class: urn:content-classes:calendarmessage\n"; //Create Email Body (HTML) $message .= "--$mime_boundary\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 '.$firstname.' '.$lastname.',</p>'; $message .= '<p>Here is my HTML Email / Used for Meeting Description</p>'; $message .= "</body>\n"; $message .= "</html>\n"; $message .= "--$mime_boundary\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:PUBLISH BEGIN:VEVENT 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 CLASS:PUBLIC END:VEVENT END:VCALENDAR'; $message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST;charset=utf-8\n'; $message .= 'Content-Type: text/calendar;name="meeting.ics";method=REQUEST\n'; $message .= "Content-Transfer-Encoding: 8bit\n\n"; $message .= $ical; $mail_vars = array( 'from_name' => $from_name, 'from' => $from_address, 'to' => $email, 'subject' => $subject, 'headers' => $headers, 'body' => $message, ); echo "<pre>"; //print_r($mail_vars); echo "</pre>";

Note : I didn't mention the mail() function here if I send this through simple mail() function, It is working fine. But, If I send the same mail using CURL, I am not getting the .ics file attachment and also the mail is not formatted. Simply, the mail looks like this

This is the CURL code

first way : $ch = curl_init($posturl); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS,$vars); curl_setopt($ch, CURLOPT_HEADER,0); // DO NOT RETURN HTTP HEADERS curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE CONTENTS OF THE CALL $Rec_Data = curl_exec($ch); second way : $ch = curl_init($posturl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $mailparams['headers']); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $userpwd); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_POSTFIELDS, $body); $Rec_Data = curl_exec($ch);

If I use the first way, I can able to send the mail, but that is not formatted. In the second way, the mail is not going.

Please check and let me know. Thanks in advance!

最满意答案

即使我也尝试过卷曲,但对我来说这是不可能的。 所以,我终于使用了简单的邮件功能。 它快速而简单。 去吧。

Even I too tried to work with curl, but its not possible for me. So, I finally worked with the simple mail function. It is fast and easy. Go for it.

更多推荐

本文发布于:2023-07-22 12:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219895.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日历   邮件   事件   通知   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!