我正在用codeigniter中的发送网格发送附件邮件。邮件发送成功,但下载后无法显示附件文件。我的代码:-
public function test() {
$attach = base_url()."/uploads/a.png";
$this->SendMail('asheesh9308@gmail.com', 'asheesh9308@gmail.com', 'sss sub', 'ss msg',$attach, 'dss.png');
}
发送网格API
function SendMail($from, $email, $subject, $message, $attach = '', $filename = '')
{
$url = 'https://api.sendgrid.com/';
$user = 'XXXXXX';
$pass = 'XXXXXX';
if ($attach <> '' && $filename <> '') {
$params = array(
'api_user' => $user,
'api_key' => $pass,
'to' => $email,
'fromname' => $from,
'from' => $from,
'subject' => $subject,
'html' => $message,
'files[' . $filename . ']' => new 'CurlFile($attach),
'files[' . $filename . ']' => '@' . $attach,
);
} else {
$params = array(
'api_user' => $user,
'api_key' => $pass,
'to' => $email,
'fromname' => $from,
'from' => $from,
'subject' => $subject,
'html' => $message);
}
$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);
// Tell PHP not to use SSLv3 (instead opting for TLS)
//curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);
return true;
}
您需要以不同的方式附加文件,将更多参数传递到Curlfile构造函数中,如
new CurlFile('filename.png', 'image/png', 'filename.png')
检查这些链接a和b