イベント カレンダーを 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 ファイルの添付ファイルが取得されず、メールがフォーマットされません。簡単に言うと、メールはこんな感じ
これはカールコードです
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);
最初の方法を使用すると、メールを送信できますが、フォーマットされていません。2番目の方法では、メールは行きません。
確認してお知らせください。前もって感謝します!