我想知道是否有人可以帮助我解决我在研究 Laravel 和通过 Mandrill 入站电子邮件处理相关问题时遇到的一些问题。
基本上我希望能够通过 Mandrill 接收电子邮件并将它们存储在我的 Laravel 数据库中。现在我不确定我是否用错误的眼光阅读文档,但 Mandrill 说它处理入站电子邮件和出站电子邮件,但是我开始认为 Mandrill 处理入站电子邮件详细信息而不是实际入站电子邮件,例如消息是否已发送等。
我创建了一个新的 Mandrill 帐户,创建了一个 API 密钥,创建了一个入站域和我网站的相应子域(例如 inboundmail.myproject.co.uk),设置了 MX 记录,并且 MX 记录显示为有效。从那里我设置了一条路线(例如[电子邮件受保护] /cdn-cgi/l/email-protection),以及相应的 webhook (myproject.co.uk/inboundmail.php),并在此 webhook 中尝试了 API 中给出的各种示例(https://mandrillapp.com/api/docs/inbound.php.html https://mandrillapp.com/api/docs/inbound.php.html),例如添加新路由、检查路由并尝试添加新域。所有这些都有效并产生了正确的结果,因此我对 Mandrill 的身份验证没有问题,但我真正的问题是是否有一个特定的 Webhook 来处理接受传入邮件消息?
我情不自禁地感觉自己像个十足的白痴问这个问题,因为我确信答案要么就在我面前,要么通过山魈不可能。
提前致谢。
感谢 duellsy 和 debest 的帮助,最后我找到了一个脚本并对其进行了扩展,将邮件添加到我自己的数据库中并相应地设计/显示它。希望这对可能遇到同样问题的人有所帮助:
<?php
require 'mandrill.php';
define('API_KEY', 'Your API Key');
define('TO_EMAIL', '[email protected] /cdn-cgi/l/email-protection');
define('TO_NAME', 'Foo Bar');
if(!isset($_POST['mandrill_events'])) {
echo 'A mandrill error occurred: Invalid mandrill_events';
exit;
}
$mail = array_pop(json_decode($_POST['mandrill_events']));
$attachments = array();
foreach ($mail->msg->attachments as $attachment) {
$attachments[] = array(
'type' => $attachment->type,
'name' => $attachment->name,
'content' => $attachment->content,
);
}
$headers = array();
// Support only Reply-to header
if(isset($mail->msg->headers->{'Reply-to'})) {
$headers[] = array('Reply-to' => $mail->msg->headers->{'Reply-to'});
}
try {
$mandrill = new Mandrill(API_KEY);
$message = array(
'html' => $mail->msg->html,
'text' => $mail->msg->text,
'subject' => $mail->msg->subject,
'from_email' => $mail->msg->from_email,
'from_name' => $mail->msg->from_name,
'to' => array(
array(
'email' => TO_EMAIL,
'name' => TO_NAME,
)
),
'attachments' => $attachments,
'headers' => $headers,
);
$async = false;
$result = $mandrill->messages->send($message, $async);
print_r($result);
} catch(Mandrill_Error $e) {
// Mandrill errors are thrown as exceptions
echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
// A mandrill error occurred: Mandrill_PaymentRequired - This feature is only available for accounts with a positive balance.
throw $e;
}
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)