Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用mandrill发送多封电子邮件_Php_Email_Mandrill - Fatal编程技术网

Php 使用mandrill发送多封电子邮件

Php 使用mandrill发送多封电子邮件,php,email,mandrill,Php,Email,Mandrill,我有一个我想向其发送相同电子邮件的订阅者数据库。我正在使用Mandrill来发送电子邮件。网站管理员必须输入电子邮件的主题、消息和附件,然后将其提交给所有订阅者 我已经尝试过做一个while循环,为数据库中的每封电子邮件运行mandrillapi。它可以工作,但服务器在发送大约5封电子邮件后会耗尽精力并崩溃 我还知道,为了能够一次运行mandrillapi并发送多封电子邮件,mandrillapi中的“to”数组必须对每个电子邮件地址重复。我试图做的事情是获得某种循环,在Mandrill API

我有一个我想向其发送相同电子邮件的订阅者数据库。我正在使用Mandrill来发送电子邮件。网站管理员必须输入电子邮件的主题、消息和附件,然后将其提交给所有订阅者

我已经尝试过做一个while循环,为数据库中的每封电子邮件运行mandrillapi。它可以工作,但服务器在发送大约5封电子邮件后会耗尽精力并崩溃

我还知道,为了能够一次运行mandrillapi并发送多封电子邮件,mandrillapi中的“to”数组必须对每个电子邮件地址重复。我试图做的事情是获得某种循环,在Mandrill API中为每封电子邮件重复“to”数组,从而运行整个API一次并发送所有电子邮件。下面是我用来发送电子邮件的mandrillapi

你们能帮帮我吗

谢谢

        while($row = mysqli_fetch_assoc($result1))
        {
            $ID = $row['ID'];
            $name = $row['name'];
            $surname = $row['surname'];
            $email = $row['email'];

            try
            {   
                $mandrill = new Mandrill('My Key');

                $message = array(
                    'html' => $message,
                    'subject' => $subject,
                    'from_email' => 'email@gmail.com',
                    'from_name' => 'Silvan Theuma',
                    'to' => array(
                        array(
                            'email' => $email,
                            'name' => $name,
                            'type' => 'to'
                        )
                    ),/*This is what I want to repeat for every email*/
                    'attachments' => array(
                        array(
                            'type' => $mimeType,
                            'name' => $attachmentName,
                            'content' => $file_encoded
                        )
                    ),                     
                );
            $async = false;
            $ip_pool = 'Main Pool';
            $result = $mandrill->messages->send($message, $async, $ip_pool);
            }

            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;
            }
       }

while
循环中构建收件人数组

while($row = mysqli_fetch_assoc($result1)){
    $recipients[] = array(
        'email' => $row['email'],
        'name' => $row['name'] . ' ' . $row['surname'],
        'type' => 'to'
    );
}
并将其传递给mandrill构造

try{   
    $mandrill = new Mandrill('My Key');

    $message = array(
        'html' => $message,
        'subject' => $subject,
        'from_email' => 'email@gmail.com',
        'from_name' => 'Silvan Theuma',
        'to' => $recipients, // here
        'preserve_recipients' => false,
        'attachments' => array(
            array(
                'type' => $mimeType,
                'name' => $attachmentName,
                'content' => $file_encoded
            )
        ),                     
    );

    $async = false;
    $ip_pool = 'Main Pool';
    $result = $mandrill->messages->send($message, $async, $ip_pool);
}

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;
}
并确保在
$message
数组中将
preserve_recipients
添加为false

preserve_recipients:是否将每个电子邮件的“收件人”标题中的所有收件人公开


你用的是什么Mandrill库?我用的是从他们网站下载的PHP库。你试过了吗?
to
数组不会重复,它是一个包含接收者列表的数组。很抱歉,前面的消息是我在代码中犯的错误