电子邮件中的动态附件文件|发送表格|的PHP

时间:2018-09-19 12:12:30

标签: php api curl sendgrid sendgrid-api-v3

以下代码具有用于在电子邮件中附加一个文件的静态文件路径。请指导我如何使其更具动态性,以便添加更多文件或通过从文件夹/目录浏览。

$fileName = 'error_log';
$filePath = dirname(__FILE__);
$params = array(
'api_user'  => $user,
'api_key'   => $pass,
'to'        => 'abc@gmail.com',
'subject'   => 'test of file sends',
'html'      => '<p> the HTML </p>',
'text'      => 'the plain text',
'from'      => 'abc@gmail.com',
'files['.$fileName.']' => '@'.$filePath.'/'.$fileName
);

print_r($params);

$request =  $url.'api/mail.send.json';
$session = curl_init($request);
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
print_r($response);

0 个答案:

没有答案