【问题标题】:Send emails in php using mandrill使用 mandrill 在 php 中发送电子邮件
【发布时间】:2014-09-17 08:08:57
【问题描述】:

我是 mandrill 的新手,我正在使用 mandrill 在我的 php 应用程序中发送邮件。此外,我已经在 mandril 中注册了我的域名。我得到了在 php 中用 mandrill 发送邮件的代码。我试过了,它的工作原理。但是我不明白如何在代码中不指定发件人地址的情况下发送邮件。那就是“发件人”邮件地址应该是我设置的默认值。

我搜索了很多,甚至在 mandrill 但我找不到任何答案。任何人都可以帮我解决这个问题吗??

我使用了这个代码:

<?php
try {
$mandrill = new Mandrill('YOUR_API_KEY');
$message = array(
    'html' => '<p>Example HTML content</p>',
    'text' => 'Example text content',
    'subject' => 'example subject',
    'from_email' => 'message.from_email@example.com', //this address should be my default one
    'from_name' => 'Example Name',
    'to' => array(
        array(
            'email' => 'recipient.email@example.com',
            'name' => 'Recipient Name',
            'type' => 'to'
        )
    ),
    'headers' => array('Reply-To' => 'message.reply@example.com'),
    'important' => false,
    'track_opens' => null,
    'track_clicks' => null,
    'auto_text' => null,
    'auto_html' => null,
    'inline_css' => null,
    'url_strip_qs' => null,
    'preserve_recipients' => null,
    'view_content_link' => null,
    'bcc_address' => 'message.bcc_address@example.com',
    'tracking_domain' => null,
    'signing_domain' => null,
    'return_path_domain' => null,
    'merge' => true,
    'global_merge_vars' => array(
        array(
            'name' => 'merge1',
            'content' => 'merge1 content'
        )
    ),
    'merge_vars' => array(
        array(
            'rcpt' => 'recipient.email@example.com',
            'vars' => array(
                array(
                    'name' => 'merge2',
                    'content' => 'merge2 content'
                )
            )
        )
    ),
    'tags' => array('password-resets'),
    'subaccount' => 'customer-123',
    'google_analytics_domains' => array('example.com'),
    'google_analytics_campaign' => 'message.from_email@example.com',
    'metadata' => array('website' => 'www.example.com'),
    'recipient_metadata' => array(
        array(
            'rcpt' => 'recipient.email@example.com',
            'values' => array('user_id' => 123456)
        )
    ),
    'attachments' => array(
        array(
            'type' => 'text/plain',
            'name' => 'myfile.txt',
            'content' => 'ZXhhbXBsZSBmaWxl'
        )
    ),
    'images' => array(
        array(
            'type' => 'image/png',
            'name' => 'IMAGECID',
            'content' => 'ZXhhbXBsZSBmaWxl'
        )
    )
);
$async = false;
$ip_pool = 'Main Pool';
$send_at = 'example send_at';
$result = $mandrill->messages->send($message, $async, $ip_pool, $send_at);
print_r($result);
/*
Array
(
    [0] => Array
        (
            [email] => recipient.email@example.com
            [status] => sent
            [reject_reason] => hard-bounce
            [_id] => abc123abc123abc123abc123abc123
        )

)
*/
} 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_Unknown_Subaccount - No subaccount exists with the id 'customer-123'
throw $e;
}
?>

【问题讨论】:

  • 如果我没记错 Mandrill Api,没有 from_email 就无法发送邮件,希望他只使用 Mandrill 帐户电子邮件。只有“from_name”是可选的
  • 我知道 from_email 对于发送邮件是不可避免的。但我的问题是我已经在 mandrill 中添加了我的域,当我发送邮件时,“发件人”地址应该是我添加为我的域的地址。怎么办??

标签: php email mandrill


【解决方案1】:

您不能设置默认的 from_address。您每次都必须通过 API 调用包含它。

您的域是另一回事,通过添加一个域,您可以将其添加到可以通过 API 与您的 Mandrill 帐户通信的域的白名单中。

【讨论】:

  • 现在我明白了这个问题。谢谢
猜你喜欢
  • 2014-05-04
  • 2013-06-22
  • 2013-10-13
  • 2013-11-26
  • 2016-02-28
  • 2023-03-28
  • 2014-03-03
  • 2013-01-06
相关资源
最近更新 更多