我在表单中使用SendGrid Api和PHP cURL。我的目标是将数据发送给网站管理员,并向填写表格的用户发送确认电子邮件。
我已成功将电子邮件发送到管理员部分,但如何同时向用户发送另一封电子邮件?请帮忙。
<?php
$url = 'https://api.sendgrid.com/';
$user = 'xyz';
$pass = 'mypass';
$params = array(
'api_user' => "$user",
'api_key' => "$pass",
'to' => "email@website.com",
'subject' => "EM Workshop Registration",
'html' => "<html><head><body> message and data goes here </body></head></html>
'from' => "admin@website.com",
);
$request = $url.'api/mail.send.json';
// Generate curl request
$session = curl_init($request);
// Tell PHP not to use SSLv3 (instead opting for TLS)
curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($session, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $sendgrid_apikey));
// Tell curl to use HTTP POST
curl_setopt ($session, CURLOPT_POST, true);
// Tell curl that this is the body of the POST
curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);
header('Location: thanks.html');
exit();
print_r($response);
?>
答案 0 :(得分:1)
您也可以使用$params
参数向用户发送电子邮件,只需将$params = array(
'api_user' => "$user",
'api_key' => "$pass",
'to' => "email@website.com",
'subject' => "EM Workshop Registration",
'html' => "<html><head><body> message and data goes here </body></head></html>
'from' => "admin@website.com",
'bcc' => "user@email.com" //JUST ADD THIS LINE
);
修改为
{{1}}