2

私たちのサイトではKohana、トランザクション メールを送信するためにphpと を使用しています。sendgrid大量gmailのスパムの問題が発生しており、オプトイン メールのみを送信し、高い開封率を実現しています。潜在的な問題の 1 つは、メールのヘッダーに 2 つのリターン パスが含まれているように見えることです。

  1. 私たちによって設定されていますKohana
  2. によって挿入されていsendgridます。

Sendgridは、メッセージを送信するときに、バウンス管理を処理するためにその「封筒」を引き継ぐと述べています。しかし、Kohana がこれを挿入しないようにする方法がわかりません。助言がありますか?コード例: Kohana は Swift を使用してメールを送信します。現在の送信方法は次のとおりです。経由で返信先を削除しようとしました

$message->headers->set('reply-to', '');

しかし、うまくいかないようです。面白いことに、空でない値に設定すると変更されますが、完全に取り除く方法はないようです。

この関数の完全なコード:

/**
 * Send an email message.
 *
 * @param   string|array  recipient email (and name), or an array of To, Cc, Bcc names
 * @param   string|array  sender email (and name)
 * @param   string        message subject
 * @param   string        message body
 * @param   boolean       send email as HTML
 * @param   string        Reply To address. Optional, default null, which defaults to From address
 * @return  integer       number of emails sent
 */
public static function send($category, $to, $from, $subject, $message, $html = FALSE, $replyto = null)
{
    // Connect to SwiftMailer
    (email::$mail === NULL) and email::connect();

    // Determine the message type
    $html = ($html === TRUE) ? 'text/html' : 'text/plain';

// Append mixpanel tracking pixel to html emails
if ($html) {
  $mixpanel_token = FD_DEV_MODE ? "08c59f4e26aa718a1038459af75aa559" : "d863dc1a3a6242dceee1435c0a50e5b7";
  $json_array = '{ "event": "e-mail opened", "properties": { "distinct_id": "' . $to . '", "token": "' . $mixpanel_token . '", "time": ' . time() . ', "campaign": "' . $category . '"}}';
  $message .= '<img src="http://api.mixpanel.com/track/?data=' . base64_encode($json_array) . '&ip=1&img=1"></img>';
}

    // Create the message
    $message = new Swift_Message($subject, $message, $html, '8bit', 'utf-8');

// Adding header for SendGrid, added by David Murray
$message->headers->set('X-SMTPAPI', '{"category" : "' . $category . '"}');

    if (is_string($to))
    {
        // Single recipient
        $recipients = new Swift_Address($to);
    }
    elseif (is_array($to))
    {
        if (isset($to[0]) AND isset($to[1]))
        {
            // Create To: address set
            $to = array('to' => $to);
        }

        // Create a list of recipients
        $recipients = new Swift_RecipientList;

        foreach ($to as $method => $set)
        {
            if ( ! in_array($method, array('to', 'cc', 'bcc')))
            {
                // Use To: by default
                $method = 'to';
            }

            // Create method name
            $method = 'add'.ucfirst($method);

            if (is_array($set))
            {
                // Add a recipient with name
                $recipients->$method($set[0], $set[1]);
            }
            else
            {
                // Add a recipient without name
                $recipients->$method($set);
            }
        }
    }

    if (is_string($from))
    {
        // From without a name
        $from = new Swift_Address($from);
    }
    elseif (is_array($from))
    {
        // From with a name
        $from = new Swift_Address($from[0], $from[1]);
    }

    // Reply To support, not standard in Swift, added by Soham
    if (!$replyto) $replyto = $from;

    $message->setReplyTo($replyto);

    return email::$mail->send($message, $recipients, $from);
}
4

2 に答える 2

1

Swiftmailer は Kohana フレームワークに標準装備されていないため、これは実際には Kohana に関する質問ではなく、Swiftmailer に関する質問です。Swiftmailer docsによると、Return-Path を明示的に設定/取得できます。

$message->setReturnPath('bounces@address.tld');

これが役立つことを願っています!

于 2013-02-06T10:53:58.770 に答える