私たちはSwiftmailerとMandrillを使って電子メールシステムを構築しました。本当に素晴らしいですが、今度はウェブフックを統合して、バウンス/失敗/失敗のアラートをトリガーしたいと考えています。Symfony2、Swiftmailer、Mandrill応答を取得
この時点で、送信された各メールに固有のIDを持つカスタムヘッダーを追加し、 Webhookが起動します。
これはうまくいきますが、私たちが使用できる_idを既に使用していますので、その上に別の一意のIDを追加しないようにしています。 symfonyのには、この応答を取り戻すためではSwiftMailerのいずれかの方法はあり
[
{
"email": "[email protected]",
"status": "sent",
"reject_reason": "hard-bounce",
"_id": "abc123abc123abc123abc123abc123"
}
]
:
マンドリルのようなもので応答しますか? (後で使用するために_id
を読み込んで保存できるように)
私はMandrillのphp SDKを使用できますが、Swiftmailerの使用を継続したいと考えています。 here
<?php
include_once "swift_required.php";
$subject = 'Hello from Mandrill, PHP!';
$from = array('[email protected]' =>'Your Name');
$to = array(
'[email protected]' => 'Recipient1 Name',
'[email protected]' => 'Recipient2 Name'
);
$text = "Mandrill speaks plaintext";
$html = "<em>Mandrill speaks <strong>HTML</strong></em>";
$transport = Swift_SmtpTransport::newInstance('smtp.mandrillapp.com', 587);
$transport->setUsername('MANDRILL_USERNAME');
$transport->setPassword('MANDRILL_PASSWORD');
$swift = Swift_Mailer::newInstance($transport);
$message = new Swift_Message($subject);
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($to);
$message->addPart($text, 'text/plain');
if ($recipients = $swift->send($message, $failures))
{
echo 'Message successfully sent!';
} else {
echo "There was an error:\n";
print_r($failures);
}
?>
swiftmailerからメッセージを送信する際には、Mandatoryを使ってメッセージを送信する必要がありますその答えはおそらくそのパッケージのどこかにあるからです。 –