【发布时间】:2020-11-06 18:52:01
【问题描述】:
我正在尝试通过 AWS 简单电子邮件服务 (SES) 自动生成日历邀请并通过 SMTP 发送它们。发送是通过 PHPMailer 完成的,似乎可以与其他 SMTP 服务器(未经验证)一起使用,但不适用于 AWS。
似乎在通过 SES 发送时,它会触发亚马逊调整内容标题。不知道如何继续,感谢任何帮助,因为我必须使用亚马逊作为发送地址。
谢谢
错误:
SMTP ERROR: DATA END command failed: 554 Transaction failed: Duplicate header 'Content-Type'.
代码:
// PHPMailer Parameters
$cal_mail = new PHPMailer(true);
//$mail->isSMTP(); // Send using SMTP
$cal_mail->SMTPDebug = 1; // Enable verbose debug output
$cal_mail->SMTPAuth = $smtp_auth; // Enable SMTP authentication
$cal_mail->SMTPSecure = 'tls';
$cal_mail->Host = $smtp_host; // Set the SMTP server to send through
$cal_mail->Port = $smtp_port;
$cal_mail->SMTPKeepAlive = true;
$cal_mail->Mailer = "smtp";
$cal_mail->Username = $smtp_username; // SMTP username
$cal_mail->Password = $smtp_password; // SMTP password
$cal_mail->AddAddress($to_email, $name); // Add a recipient
$cal_mail->SetFrom($from_email, $from_name);
$cal_mail->AddReplyTo($to_email, $to_name);
$cal_mail->isHTML(false); // calendar must be FALSE
$cal_mail->ContentType = 'text/calendar';
$cal_mail->Subject = "Outlook Event";
$cal_mail->addCustomHeader('MIME-version', "1.0");
$cal_mail->addCustomHeader('Content-type', "text/calendar; method=REQUEST; charset=UTF-8");
$cal_mail->addCustomHeader('Content-Transfer-Encoding', "7bit");
$cal_mail->addCustomHeader('X-Mailer', "Microsoft Office Outlook 12.0");
$cal_mail->addCustomHeader("Content-class: urn:content-classes:calendarmessage");
// Create Calendar Body
$ical = "BEGIN:VCALENDAR\r\n";
$ical .= "VERSION:2.0\r\n";
$ical .= "PRODID:-//BPNSolutions//SalesDept//EN\r\n";
$ical .= "METHOD:REQUEST\r\n";
$ical .= "BEGIN:VEVENT\r\n";
$ical .= "ORGANIZER;SENT-BY=\"MAILTO:noreply@mail.com\":MAILTO:noreply@mail.com\r\n";
$ical .= "ATTENDEE;CN=" . $to_email . ";ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;RSVP=TRUE:MAILTO:" . $to_email . "\r\n";
$ical .= "UID:" . strtoupper(md5($event_id)) . "-bpn-solutions.com\r\n";
$ical .= "SEQUENCE:" . $sequence . "\r\n";
$ical .= "STATUS:" . $status . "\r\n";
$ical .= "DTSTAMP;TZID=Etc/UTC:" . date('Ymd') . 'T' . date('His') . "\r\n";
$ical .= "DTSTART:" . $start . "T" . $start_time . "\r\n";
$ical .= "DTEND:" . $end . "T" . $end_time . "\r\n";
$ical .= "LOCATION:" . $venue . "\r\n";
$ical .= "SUMMARY:" . $summary . "\r\n";
$ical .= "DESCRIPTION:" . $event['description'] . "\r\n";
$ical .= "BEGIN:VALARM\r\n";
$ical .= "TRIGGER:-PT15M\r\n";
$ical .= "ACTION:DISPLAY\r\n";
$ical .= "DESCRIPTION:Reminder\r\n";
$ical .= "END:VALARM\r\n";
$ical .= "END:VEVENT\r\n";
$ical .= "END:VCALENDAR\r\n";
编辑 1:
下面的代码成功生成了一封带有.ics 附件的电子邮件,但桌面版 MS Outlook 无法打开/阅读附件,在预览电子邮件时分别不会触发任何接受/拒绝按钮。不过,同样的附件在 Outlook / Apple Mail for iOS 上也能正常工作。
// Create Calendar Body
$ical = "BEGIN:VCALENDAR\r\n";
$ical .= "VERSION:2.0\r\n";
$ical .= "PRODID:-//Company//SalesDept//EN\r\n";
$ical .= "METHOD:REQUEST\r\n";
$ical .= "NAME: Test1\r\n";
$ical .= "X-WR-CALNAME:Test Calendar\r\n";
$ical .= "BEGIN:VEVENT\r\n";
$ical .= "ORGANIZER;CN=\"Company Name:mailto:noreply@domain.com\r\n";
$ical .= "ATTENDEE;CN=" . $to_email . ";ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;RSVP=TRUE:MAILTO:" . $to_email . "\r\n";
$ical .= "UID:" . md5(uniqid(mt_rand(), true)) . "domain.com\r\n";
$ical .= "SEQUENCE:" . $sequence . "\r\n";
$ical .= "STATUS:" . $status . "\r\n";
$ical .= "DTSTART:" . $start . "T" . $start_time . "Z\r\n";
$ical .= "DTEND:" . $end . "T" . $end_time . "Z\r\n";
$ical .= "DTSTAMP:" . date('Ymd') . 'T' . date('His') . "Z\r\n";
$ical .= "LOCATION:" . $venue . "\r\n";
$ical .= "SUMMARY:" . $summary . "\r\n";
$ical .= "DESCRIPTION:Some descriptive text here.\r\n";
$ical .= "BEGIN:VALARM\r\n";
$ical .= "TRIGGER:-PT15M\r\n";
$ical .= "ACTION:DISPLAY\r\n";
$ical .= "DESCRIPTION:Reminder\r\n";
$ical .= "END:VALARM\r\n";
$ical .= "END:VEVENT\r\n";
$ical .= "END:VCALENDAR\r\n";
$cal_mail->ContentType = 'text/calendar';
$cal_mail->Subject = $summary;
$cal_mail->Body = "This is the body text which is meant to be shown in the email body";
$cal_mail->AltBody = $ical;
$cal_mail->Ical = $ical;
【问题讨论】:
标签: php phpmailer amazon-ses