電子郵件是從相同的代碼發送的,現在我在添加附件代碼后從 sandgrid api 收到“找不到資源”錯誤,“sendgrid/sendgrid”:“~6.0”和“laravel/framework”:“5.4.*”,$from = new SendGrid\Email($data['from_name'], $data['from']);$subject = $data['subject'];$to = new SendGrid\Email("user","[email protected]");$content = new SendGrid\Content("text/html", $data['view']);$mail = new SendGrid\Mail($from, $subject, $to, $content);$apiKey = getenv('SENDGRID_API_KEY');$sg = new \SendGrid($apiKey);$response = $sg->client->mail();//Attachment code startif(isset($data['attach_files']) && is_array($data['attach_files']) && count($data['attach_files'])>=1){ foreach($data['attach_files'] as $attach_files_i=>$attach_files_path){ $filename = basename($attach_files_path); $file_encoded = base64_encode(file_get_contents($attach_files_path)); //echo '<pre>--$filename';print_r($filename);echo '</pre>'; //working fine //echo '<pre>--$file_encoded';print_r($file_encoded);echo '</pre>'; //working fine //echo '<pre>--mime_content_type($attach_files_path)';print_r(mime_content_type($attach_files_path));echo '</pre>'; //working fine $attachment = new SendGrid\Attachment(); $attachment->setType(mime_content_type($attach_files_path)); $attachment->setContent($file_encoded); $attachment->setDisposition("attachment"); $attachment->setFilename($filename); $response->addAttachment($attachment); }}//Attachment code end$response = $response->send()->post($mail);echo "<pre>"; print_r($response); die;
2 回答

互換的青春
TA貢獻1797條經驗 獲得超6個贊
刪除函數 base64_encode 是錯誤的
$attachment = new \SendGrid\Attachment();
$attachment->setContent(file_get_contents($attach_files_path));
$attachment->setType(mime_content_type($attach_files_path));
$attachment->setFilename($filename);
$attachment->setDisposition("attachment");
$mail->addAttachment($attachment);
- 2 回答
- 0 關注
- 93 瀏覽
添加回答
舉報
0/150
提交
取消