0
您好我想在php中使用SendGrid example发送电子邮件。我确实收到附件的电子邮件。SendGrid API附件加载不正确
但是,当我点击附件,我得到的消息,该文件已损坏。附件的原始文件大小是768 Kb,但是当我在电子邮件客户端中得到它时,它只有0.1Kb。
此外,我检查和附件文件是在同一目录中的PHP应用程序。
我在这里做错了什么?
这里是我使用
$url = 'https://api.sendgrid.com/';
$user = 'MY_USER_ID';
$pass = 'MY_PASSWORD';
$fileName = 'week-19.pdf';
$filePath = dirname(__FILE__);
$params = array(
'api_user' => $user,
'api_key' => $pass,
'to' =>'[email protected]',
'subject' => 'Sendgrid test of file sends',
'html' => '<p> the HTML </p>',
'text' => 'the plain text',
'from' => '[email protected]',
'files['.$fileName.']' => '@'.$filePath.'/'.$fileName
);
print_r($params);
$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);
谢谢Seema - 它适用于我。 –
对我来说也是.. :) – Mohanish