我正在尝试使用Sendgrid网络API将表单中的附件发送到电子邮件。
但是,我不知道如何编辑以下代码以便使用表单的输入文件。
请帮忙吗?
$params = array(
'api_user' => $user,
'api_key' => $pass,
'to' => 'the recipient email',
'subject' => 'New Careers',
'html' => $email,
'text' => $email,
'from' => 'the sender email',
);
$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);
答案 0 :(得分:0)
此解决方案可能会对您有所帮助。
if (function_exists('curl_file_create')) { // php 5.5+
$cFile = curl_file_create($file_name_with_full_path);
} else { //
$cFile = '@' . realpath($file_name_with_full_path);
}
$post = array('extra_info' => '123456','file_contents'=> $cFile);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
curl_close ($ch);