我想使用 Sendgrid WebAPI 最好不使用 SMTP 或 Swiftmailer 使用下面的代码。是否可以将整个动态网页传递给 'html' $params 数组而不创建长字符串变量并且需要转义每个引号并回显每个变量?每封电子邮件差异很大,因此 Sendgrid 的模板/邮件合并选项对我不起作用。谢谢!
这是一个简单的 html 示例(我的有更多动态内容):
<html>
<head></head>
<body>
<p>Hi I'm <?php echo $name; ?>!<br>
<span style="color: #999999; font-size: 11px;">How are you?</span><br>
</p>
</body>
</html>
$url = 'http://sendgrid.com/';
$user = 'USERNAME';
$pass = 'PASSWORD';
$params = array(
'api_user' => $user,
'api_key' => $pass,
'to' => 'example3@sendgrid.com',
'subject' => 'testing from curl',
'html' => 'testing body',
'text' => 'testing body',
'from' => 'example@sendgrid.com',
);
$request = $url.'api/mail.send.json';
// Generate curl request
$session = curl_init($request);
// 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);
// print everything out
print_r($response);