猿问

如何为swift mailer php传递多个标头

我正在使用 php 在 Outlook 中创建会议,我发现了几个例子并尝试实现它的工作,但它正在使用php mail() method,在 php 邮件方法中我知道如何传递标题,但我想要实现的项目正在使用 swift mailer 和我不知道如何在 swift mailer 中定义这些标题,以下是一个使用 php mail() 的工作示例


$from_name = "Some One";        

$from_address = "def@abc.com";        

$to_name = "Soem Two";        

$to_address = "xyz@abc.com";        


$date               = '20190905';

$startTime          = '13:20:00';

$endTime            = '19:00:00';   


$subject = "Standup Meeting";        

$description = "The purpose of the meeting is to discuss works done and inprogress";        

$location = "ABCD EFGH";

$domain = 'mydomain.com';


//Create Email Headers

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


$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\r\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 '.$to_name.',</p>';

$message .= '<p>'.$description.'</p>';

$message .= "</body>\n";

$message .= "</html>\n";

$message .= "--$mime_boundary\r\n";


$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" .


但我想在 swift mailer 中使用这个我不知道如何为 swift mailer 创建标题以及如何在 swift 撰写电子邮件时通过任何人可以帮助我想要这个。



喵喵时光机
浏览 112回答 1
1回答

慕的地8271018

您正在使用 swiftmailer 以避免需要自己设置标题。您可以发送带有您需要的标题的邮件,如下所示:$from_name = "Some One";$from_address = "def@abc.com";$to_name = "Soem Two";$to_address = "xyz@abc.com";$date&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= '20190905';$startTime&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = '13:20:00';$endTime&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = '19:00:00';$subject = "Standup Meeting";$description = "The purpose of the meeting is to discuss works done and inprogress";$location = "acfr ffs";$domain = 'my.com';/**&nbsp;* @var \yii\swiftmailer\Message $mail&nbsp;*/$mail=Yii::$app->mailer->compose()&nbsp; &nbsp; ->setFrom([$from_address => $from_name])&nbsp; &nbsp; ->setReplyTo([$from_address => $from_name])&nbsp; &nbsp; ->setSubject($subject)&nbsp; &nbsp; ->setTo([$to_address => $to_name]);$mail->addHeader('Content-class', 'urn:content-classes:calendarmessage');//Create Email Body (HTML)$message = "<html>\n";$message .= "<body>\n";$message .= '<p>Dear '.$to_name.',</p>';$message .= '<p>'.$description.'</p>';$message .= "</body>\n";$message .= "</html>\n";$ical = 'BEGIN:VCALENDAR' . "\r\n" .&nbsp; &nbsp; ... skipped the body for better readability ...&nbsp; &nbsp; 'END:VCALENDAR'. "\r\n";$swiftMail = $mail->getSwiftMessage();$swiftMail->setContentType('multipart/alternative');$swiftMail->addPart($message, 'text/html');$swiftMail->addPart(&nbsp; &nbsp; $ical,&nbsp; &nbsp; 'text/calendar;name="meeting.ics";method=REQUEST',&nbsp; &nbsp; null);$mail->send();如果您不需要这个特定的标题并且您的目标只是发送日历事件,您可以让它变得更加简单$from_name = "Some One";$from_address = "def@abc.com";$to_name = "Soem Two";$to_address = "xyz@abc.com";$date&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= '20190905';$startTime&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = '13:20:00';$endTime&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = '19:00:00';$subject = "Standup Meeting";$description = "The purpose of the meeting is to discuss works done and inprogress";$location = "cfrt hjd";$domain = 'my.com';$mail=Yii::$app->mailer->compose()&nbsp; &nbsp; ->setFrom([$from_address => $from_name])&nbsp; &nbsp; ->setReplyTo([$from_address => $from_name])&nbsp; &nbsp; ->setSubject($subject)&nbsp; &nbsp; ->setTo([$to_address => $to_name]);//Create Email Body (HTML)$message = "<html>\n";$message .= "<body>\n";$message .= '<p>Dear '.$to_name.',</p>';$message .= '<p>'.$description.'</p>';$message .= "</body>\n";$message .= "</html>\n";$ical = 'BEGIN:VCALENDAR' . "\r\n" .&nbsp; &nbsp; ... skipped the body for better readability ...&nbsp; &nbsp; 'END:VCALENDAR'. "\r\n";$mail->setHtmlBody($message);$mail->attachContent(&nbsp; &nbsp; $ical,&nbsp; &nbsp; [&nbsp; &nbsp; &nbsp; &nbsp; 'contentType' => 'text/calendar;name="meeting.ics";method=REQUEST'&nbsp; &nbsp; ]);$mail->send();
随时随地看视频慕课网APP
我要回答