【发布时间】:2015-07-11 22:27:40
【问题描述】:
我正在构建一个基于 WordPress 的交付网站。在每笔交易中,我都会使用 SendGrid 和 cURL 发送一封包含 HTML 内容的电子邮件。该电子邮件还将被传真给一些用户(使用 RingCentral - 另一个第三方服务)。问题是,上下文也应该作为附件发送。
如果我使用静态文件 (test.txt),一切正常。
我需要将内容 ("$email_heada {$_message[$eid]} $email_foota") 作为附件发送。可能存在并发问题(多个用户同时发送电子邮件等)
以下是我当前的代码:
$fileName = 'test.txt';
$filePath = dirname(__FILE__);
$params = array(
'api_user' => $sendgridusername,
'api_key' => $sendgridpassword,
'to' => $email,
'subject' => $mySubject,
'html' => "$email_heada {$_message[$eid]} $email_foota",
'text' => "$email_heada {$_message[$eid]} $email_foota",
'from' => $settings_general->pear_user,
'files['.$fileName.']' => '@'.$filePath.'/'.$fileName
);
$request = $sendgridurl.'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);
// Tell PHP not to use SSLv3 (instead opting for TLS)
curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);
有什么建议吗?谢谢之前
【问题讨论】: