1

sendmailを使用して1回の通話で複数の受信者にメールを送信したい。私はcakephp1.3を使用しています。単一の受信者にメールを送信することは問題なく機能します。複数の受信者(通常は2〜5人程度)にメールを送信できるかどうか疑問に思いました。

$this->Email->smtpOptions = array('port'=>'587', 'timeout'=>'30', 'host' => 'smtp.sendgrid.net', 'username'=>'****', 'password'=>'****', 'client' => '***');
$this->Email->delivery = 'smtp';
$this->Email->from = 'Swiso Support <support@swiso.net>';
$this->Email->to = $user['email'];
$this->Email->subject = $title;
$this->Email->template = 'email';
$this->Email->sendAs = 'both';
$this->Email->send();

受信者の配列をに渡すことはできますか$this->Email->to

助けていただければ幸いです。

4

5 に答える 5

2

「cakephpemail」をグーグルで検索すると、次のことがわかります。

CakePHP 1.3クックブック:Eメール

必要なものが得られるはずです。たとえば、bcc複数の受信者にメールを送信できるフィールドがあります。

この本には、ループで複数のメッセージを送信することに関する章もあります。

于 2011-12-03T12:02:19.743 に答える
1

私はCakePHPについてあまり知りませんが、Sendgridはphpで複数の受信者に単一のメールを送信する簡単な方法を提供し、このコードをCakephpに変換できます。

SendgridはMail::addTos、メールを送信したい複数のメールを追加できる方法を提供します。

ユーザーの電子メールとユーザー名の連想配列をに渡す必要がありますaddTos

以下の例を参照してください。

$tos = [ 
        //user emails       =>  user names  
        "user1@example.com" => "Example User1",
        "user2@example.com" => "Example User2",
        "user3@example.com" => "Example User3"
    ];
    $email->addTos($tos);

sendgrid-php githubライブラリで提供されている完全な例を見たい場合は、以下に含めたので、例全体を理解できます。

<?php
require 'vendor/autoload.php'; // If you're using Composer (recommended)
// Comment out the above line if not using Composer
// require("<PATH TO>/sendgrid-php.php");
// If not using Composer, uncomment the above line and
// download sendgrid-php.zip from the latest release here,
// replacing <PATH TO> with the path to the sendgrid-php.php file,
// which is included in the download:
// https://github.com/sendgrid/sendgrid-php/releases

$email = new \SendGrid\Mail\Mail(); 
$email->setFrom("test@example.com", "Example User");
$tos = [ 
    "test+test1@example.com" => "Example User1",
    "test+test2@example.com" => "Example User2",
    "test+test3@example.com" => "Example User3"
];
$email->addTos($tos);
$email->setSubject("Sending with Twilio SendGrid is Fun");
$email->addContent("text/plain", "and easy to do anywhere, even with PHP");
$email->addContent(
    "text/html", "<strong>and easy to do anywhere, even with PHP</strong>"
);
$sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY'));
try {
    $response = $sendgrid->send($email);
    print $response->statusCode() . "\n";
    print_r($response->headers());
    print $response->body() . "\n";
} catch (Exception $e) {
    echo 'Caught exception: '.  $e->getMessage(). "\n";
}
于 2019-06-19T06:42:38.317 に答える
0
foreach($recipients as $recipient) {
    $this->Email->to .= $recipient['email'] . ",";
}

BCCを送信することは、これを行うためのより良い方法です。受信者がBCCの送信先を確認できないようにする場合です。その場合は

$this->Email->bcc

それ以外の

$this->Email->to
于 2011-12-03T13:29:45.953 に答える
0

簡単な答え:いいえ。私もこれを調べています(Sendgridを使用)。bccフィールドを使用する場合を除いて、同じ呼び出しでそれを行う方法はありません。ただし、ループで送信することだけを心配する必要はありません。

于 2011-12-03T13:17:43.037 に答える
0

http://book.cakephp.org/1.3/en/view/1284/Class-Attributes-and-Variables

to:メッセージの宛先(文字列)。複数の受信者に電子メールを送信する場合は、アドレスをコンマで区切ります。

cc:メッセージをccするアドレスの配列。

bcc:メッセージのbcc(ブラインドカーボンコピー)へのアドレスの配列。

例:

$recipients = array("email1@gmail.com", "email2@yahoo.com");
$this->Email->to = implode(",", $recipients);
$this->Email->cc = $recipient;
$this->Email->bcc = $recipient;
于 2012-10-02T13:37:43.597 に答える