Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:使用PHP邮件发送ical_Php_Phpmailer_Icalendar_Vcal - Fatal编程技术网

PHP:使用PHP邮件发送ical

PHP:使用PHP邮件发送ical,php,phpmailer,icalendar,vcal,Php,Phpmailer,Icalendar,Vcal,我正在尝试使用php邮件发送ical 这是我的功能 function sendIcalEmail($firstname,$lastname,$email,$meeting_date,$meeting_name,$meeting_duration) { //Convert MYSQL datetime and construct iCal start, end and issue dates $meetingstamp = strtotime($meeting_date .

我正在尝试使用php邮件发送ical

这是我的功能

function sendIcalEmail($firstname,$lastname,$email,$meeting_date,$meeting_name,$meeting_duration) {



    //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 = "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 = '';
    $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;            

    //SEND MAIL


    $mail->AddAddress($email);

    $mail->Subject =  $subject;
    $mail->IsHTML(true);
    //$mail->AddAttachment($message);
    $mail->Body =$message;
    if(!$mail->Send())
    {
        $message= "Error sending: " . $mail->ErrorInfo;

    }


}
函数sendIcalEmail($firstname、$lastname、$email、$meeting\u date、$meeting\u name、$meeting\u duration){
//转换MYSQL日期时间并构造iCal开始、结束和发布日期
$meetingstamp=strottime($meeting_date.“UTC”);
$dtstart=gmdate(“Ymd\THis\Z”,$meetingstamp);
$dtend=gmdate(“Ymd\THis\Z”、$meetingstamp+$meeting\u持续时间);
$todaystamp=gmdate(“Ymd\THis\Z”);
//创建唯一标识符
$caluid=date('Ymd').'T'.date('His').“-”.rand().“@mydomain.com”;
//创建Mime边界
$mime_boundary=“----会议预订----”.md5(time());
//创建电子邮件标题
$headers=“From:”.$From\u name.\n”;
$headers.=“回复:”.$from_name.“\n”;
$headers.=“MIME版本:1.0\n”;
$headers.=“内容类型:多部分/可选;边界=\”$mime\U边界\“\n”;
$headers.=“内容类:urn:Content类:calendarmessage\n”;
//创建电子邮件正文(HTML)
$message='';
$message.=“--$mime\u边界\n”;
$message.=“内容类型:text/html;字符集=UTF-8\n”;
$message.=“内容传输编码:8位\n\n”;
$message.=“\n”;
$message.=“\n”;
$message.='亲爱的'$firstname.'.$lastname.',

'; $message.='这是我的HTML电子邮件/用于会议描述

'; $message.=“\n”; $message.=“\n”; $message.=“--$mime\u边界\n”; //创建ICAL内容(谷歌rfc 2445了解详细信息和使用示例) $ical='开始:VCALENDAR PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN 版本:2.0 方法:发布 开始:VEVENT 组织者:邮寄地址:'.$from_地址' DTSTART:“.$DTSTART.” DTEND:“.$DTEND” 地点:'.$MENTING_地点' 运输:不透明 序列:0 UID:“.$cal\u UID” DTSTAMP:“.$todaystamp.” 说明:'.$MENTING_说明' 摘要:“.$subject” 优先次序:5 类别:公共 完:维文特 完:VCALENDAR",; $message.='内容类型:文本/日历;name=“meeting.ics”;方法=请求;字符集=utf-8\n'; $message.='内容类型:文本/日历;name=“meeting.ics”;方法=请求\n'; $message.=“内容传输编码:8位\n\n”; $message.=$ical; //寄信 $mail->AddAddress($email); $mail->Subject=$Subject; $mail->IsHTML(true); //$mail->AddAttachment($message); $mail->Body=$message; 如果(!$mail->Send()) { $message=“发送错误:”.$mail->ErrorInfo; } }
我使用的是php邮件,但不幸的是,邮件不是以ical格式发送的

请告诉我我做错了什么


我也没有办法在这封邮件中发送标题。

尝试添加“多部分/备选”的内容类型。从我的一个有效功能复制(它使用PEAR的邮件):


将以下行添加到phpMailer脚本中。我花了几个小时才了解自己


$mail->AddStringAttachment(“$ical”、“$NameOfAttachment”、“base64”、“文本/日历;字符集=utf-8;方法=请求”)

对于PEAR的邮件功能来说,这可能是一个很好的解决方案,但它并没有真正回答关于PHPMailer的问题。
protected function eF_mail_multipart($sender, $recipient, $subject, $textbody, $calendarbody, $onlyText = false, $bcc = false) {

        $hdrs = array('From'    => $sender,
                'Subject' => $subject,
                //'To'      => $recipient,
                'Date' => date("r"));
        if ($bcc) {
            //$hdrs['To'] = '';
        }

        $params = array("text_charset" => "UTF-8",
                "html_charset" => "UTF-8",
                "head_charset" => "UTF-8",
                "head_encoding" => "base64");


        $textparams = array(
                'charset'       => 'utf-8',
                'content_type'  => 'text/plain',
                'encoding'      => 'base64',
        );

        $calendarparams = array(
                'charset'       => 'utf-8',
                'content_type'  => 'text/calendar;method=REQUEST',
                'encoding'      => 'base64',
        );


        $email = new Mail_mimePart('', array('content_type' => 'multipart/alternative'));

        $textmime = $email->addSubPart($textbody, $textparams);
        $htmlmime = $email->addSubPart($calendarbody, $calendarparams);


        $final = $email->encode();
        $final['headers'] = array_merge($final['headers'], $hdrs);

        $smtp = Mail::factory('smtp', array('auth'      => $GLOBALS['configuration']['smtp_auth'] ? true : false,
                'host'      => $GLOBALS['configuration']['smtp_host'],
                'password'  => $GLOBALS['configuration']['smtp_pass'],
                'port'      => $GLOBALS['configuration']['smtp_port'],
                'username'  => $GLOBALS['configuration']['smtp_user'],
                'timeout'   => $GLOBALS['configuration']['smtp_timeout'],
                'localhost' => $_SERVER["HTTP_HOST"]));

        $result = $smtp -> send($recipient, $final['headers'], $final['body']);

        return $result;
    }