【发布时间】:2021-03-22 18:39:43
【问题描述】:
<?php
if (isset($_POST['send']))
{
$email = $_POST['email'];
$subject = $_POST['subject'];
$body = $_POST['message'];
$data = array(
"personalizations" => array(
array(
"to" => array(
array(
"email" => $email,
"name" => $name
)
)
)
) ,
"from" => array(
"email" => $sender
) ,
"subject" => $subject,
"content" => array(
array(
"type" => "text/html",
"value" => $body
)
)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sendgrid.com/v3/mail/send");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
}
?>
我正在使用 Sendgrid API 通过 PHP 发送电子邮件
我可以一次发送到一封电子邮件,但是
我需要将 $email 变量作为大量电子邮件传递
array(
"email" => $email,
"name" => $name
)
$email 变量将参数设置为电子邮件集合
例如:$email="abc@mail.com,info@abc.com,def@gmail.com"
我该怎么做?
【问题讨论】:
-
<?pre不应该是<?php吗?另外:你确定isset($_POST['send'])计算结果为真吗? -
您到底想达到什么目标?如果任何变量应该以另一种格式给出,是什么阻止您更改代码中的格式?
标签: php sendgrid-api-v3 bulk-email