我正在尝试向gmail,outlook,yahoo,thunderbird,outlook express 2013和iphone发送包含HTML和Ics格式的电子邮件,但我只能将ics格式发送到gmail,outlook和yahoo。
问题我无法在同一邮件中发送html格式 我尝试使用以下代码
public function createScheduleNotification(){
$from = 'info@careervita.com';
$fromName = 'info';
$to = 'testcareervita@outlook.com';
$subject = 'Invitation for Test Demo';
$desc = 'THIS IS TEST DEMO INVITAION';
$uid = date('Ymd').'T'.date('His')."-".rand();
$message = "BEGIN:VCALENDAR\r\n";
$message.= "PRODID:-//Zoho CRM//NONSGML Calendar//EN\r\n";
$message.= "VERSION:2.0\r\n";
$message.= "X-WR-TIMEZONE:GMT\r\n";
$message.= "X-WR-CALNAME:ZCRM\r\n";
$message.= "METHOD:REQUEST\r\n";
$message.= "CALSCALE:GREGORIAN\r\n";
$message.= "BEGIN:VEVENT\r\n";
$message.= "UID:".$uid."\r\n";
$message.= "DESCRIPTION:".$desc."\r\n";
$message.= "ORGANIZER;CN= Manisha:mailto:manisha.g@careervita.com\r\n";
$message.= "DTSTART:20150710T100010Z\r\n";
$message.= "DTEND:20150710T110000Z\r\n";
$message.= "ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;CN=Vinod T:mailto:g_manisha@outlook.com\r\n";
$message.= "ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;CN=Vivek J:mailto:manisha.gaidhane8788@gmail.com\r\n";
$message.= "LOCATION:CV360\r\n";
$message.= "CREATED:20150701T060720Z\r\n";
$message.= "LAST-MODIFIED:20150701T060720Z\r\n";
$message.= "X-EVENT-OWNER:1563791000000084003\r\n";
$message.= "END:VEVENT\r\n";
$message.= "END:VCALENDAR";
Yii::import('application.extensions.phpmailer.JPhpMailer');
$mailer = new JPhpMailer(true);
if (Yum::module()->phpmailer['transport'])
switch (Yum::module()->phpmailer['transport']){
case 'smtp':
$mailer->IsSMTP();
break;
case 'sendmail':
$mailer->IsSendmail();
break;
case 'qmail':
$mailer->IsQmail();
break;
case 'mail':
default:
$mailer->IsMail();
}
else
$mailer->IsMail();
$mailer->IsHTML(true);
$mailerconf=Yum::module()->phpmailer['properties'];
if(is_array($mailerconf))
foreach($mailerconf as $key=>$value) {
if(isset(JPhpMailer::${$key}))
JPhpMailer::${$key} = $value;
else
$mailer->$key=$value;
}
$mailer->SetFrom($from);
$mailer->AddAddress($to);
$mailer->Subject = $subject;
$mailer->Body = $message;
$mailer->AddCC('testcareervita@gmail.com', 'Person One');
$mailer->AddCC('testcareervita@yahoo.in', 'Person Two');
$mailer->ContentType = 'text/calendar';
$mailer->CharSet = 'UTF-8';
$mailer->addCustomHeader("MIME-version : 1.0");
$mailer->addCustomHeader('Content-type : text/calendar; name="testcal.ics"; method=REQUEST;');
$mailer->addCustomHeader('Content-Transfer-Encoding:7bit'); //to interpret ics file
$mailer->addCustomHeader("Content-class: urn:content-classes:calendarmessage");
$mailer->addCustomHeader('Content-Disposition : inline; filename="testcal.ics"');
return $mailer->Send();
}
答案 0 :(得分:0)
你不应该添加那些自定义标题 - 它只会破坏事物。
PHPMailer包含一个名为EasyPeasyICS的简单ICS生成类。它只是非常简单,但它做了最重要的事情。有关如何使用它,请参阅this example in the test suite。
无论您是在生成它,只需将您的ics数据粘贴到$mail->Ical
中,它就会作为multipart/alternative
部分添加到text/calendar
部分,与通常的text/html
和text/plain
部分。在某些客户端中,这有点棘手且不可靠,如果您尝试同时使用附件,则可能会遇到麻烦。
不幸的是,PHPMailer不会让你构建任意的MIME结构,而且更加全面地支持iCal部分会变得太乱,特别是面对需要凌乱的解决方法的某些客户端的破坏支持,正如this issue讨论的那样