我想在单个呼叫中使用sendmail向多个收件人发送邮件。我使用的是cakephp 1.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。
我很感谢你的帮助。
发布于 2011-12-03 20:02:20
谷歌"cakephp email“显示:
CakePHP 1.3 cookbook: Email
它应该会为您提供所需的内容:例如,有一个允许您向多个收件人发送邮件的bcc字段。
这本书还有一个关于sending multiple messages in a loop.的章节
发布于 2019-06-19 14:42:38
我不太了解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";
}发布于 2011-12-03 21:17:43
简短的回答是:不。我也一直在研究这个问题(使用Sendgrid),除非你想使用密件抄送字段,否则没有办法在同一个调用中做到这一点。不过,您不必担心只是在循环中发送它们。
https://stackoverflow.com/questions/8367475
复制相似问题