如何使用sendgrid PHP发送ics.file

时间:2019-02-11 06:47:56

标签: php sendgrid

我正在使用PHPMailer将ics.file(Calnder)发送到电子邮件,但是现在我需要使用sengrid发送电子邮件,任何人都可以提供相同的代码。

我的PHPmailer代码如下所示,它现在在我的网站上正在使用,但是phpmailer出现了一些问题,所以我想使用安全,快速的sendgrid。

$mail = new PHPMailer();

$mail->IsSMTP();                           // telling the class to use SMTP

$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)

$mail->SMTPAuth   = true;                  // enable SMTP authentication

$mail->SMTPSecure = "tls"; 



$mail->Host = SMTPSERVER;

$mail->Username = SMTPUSER;  

$mail->Password = SMTPPWD;

$mail->Port = SMTPPORT;

$mail->SetFrom($from_address, $from_name);



$mail->Subject = $subject;



$to_email = trim($to_address);



$to = explode(',', $to_email);



foreach($to as $key => $value){

    $mail->AddAddress($to[$key], $to_name);

}



$cal_uid = date('Ymd').'T'.date('His')."-".rand()."@educationfolder.com";

$domain = 'educationfolder.com';



//Create Email Headers

$mime_boundary = "----Meeting Booking----".MD5(TIME());

//Create Email Headers

/*$mail->addCustomHeader("Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n");

$mail->addCustomHeader("Content-class: urn:content-classes:calendarmessage\n");*/   

  // email body

$message="X-ALT-DESC;FMTTYPE=text/html:<!DOCTYPE HTML><HTML><BODY><p>".$description."</p></BODY></HTML>";
// email body


$ical = 'BEGIN:VCALENDAR' . "\r\n" .

'PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN' . "\r\n" .

'VERSION:2.0' . "\r\n" .

'METHOD:REQUEST' . "\r\n" .

'BEGIN:VTIMEZONE' . "\r\n" .

'TZID:Eastern Time' . "\r\n" .

'BEGIN:STANDARD' . "\r\n" .

'DTSTART:20091101T020000' . "\r\n" .

'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11' . "\r\n" .

'TZOFFSETFROM:-0400' . "\r\n" .

'TZOFFSETTO:-0500' . "\r\n" .

'TZNAME:EST' . "\r\n" .

'END:STANDARD' . "\r\n" .

'BEGIN:DAYLIGHT' . "\r\n" .

'DTSTART:20090301T020000' . "\r\n" .

'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3' . "\r\n" .

'TZOFFSETFROM:-0500' . "\r\n" .

'TZOFFSETTO:-0400' . "\r\n" .

'TZNAME:EDST' . "\r\n" .

'END:DAYLIGHT' . "\r\n" .

'END:VTIMEZONE' . "\r\n" .  

'BEGIN:VEVENT' . "\r\n" .

'ORGANIZER;CN="'.$from_name.'":MAILTO:'.$from_address. "\r\n" .

'ATTENDEE;CN="'.$to_name.'";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:'.$to_address. "\r\n" .

'LAST-MODIFIED:' . date("Ymd\TGis") . "\r\n" .

'UID:'.date("Ymd\TGis", strtotime($startTime)).rand()."@".$domain."\r\n" .

'DTSTAMP:'.date("Ymd\TGis"). "\r\n" .

'DTSTART;TZID="Eastern Time":'.date("Ymd\THis", strtotime($startTime)). "\r\n" .

'DTEND;TZID="Eastern Time":'.date("Ymd\THis", strtotime($endTime)). "\r\n" .

'TRANSP:OPAQUE'. "\r\n" .

'SEQUENCE:1'. "\r\n" .

'SUMMARY:' . $subject . "\r\n".$message."\r\n".

'LOCATION:' . $location . "\r\n" .

'CLASS:PUBLIC'. "\r\n" .

'PRIORITY:5'. "\r\n" .

'BEGIN:VALARM' . "\r\n" .

'TRIGGER:-PT15M' . "\r\n" .

'ACTION:DISPLAY' . "\r\n" .

'DESCRIPTION:'. $message . "\r\n" .

'END:VALARM' . "\r\n" .

'END:VEVENT'. "\r\n" .

'END:VCALENDAR'. "\r\n";



$mail->AddStringEmbeddedImage($ical, $cal_uid, 'event.ics', 'base64', 'application/octet-stream');



$mail->ical = $ical;



$mail->MsgHTML($description);



if(!$mail->Send()) {

  echo "Mailer Error: " . $mail->ErrorInfo;

  return false;

}else{

    return true;

}

谢谢

0 个答案:

没有答案