This could be SSL cert issue. Here is the solution:
- Download cacert.pem
https://curl.haxx.se/docs/caextract.html - Store the file in C:\PHP
- Change php.ini:
curl.cainfo = c:\php\cacert.pem - Restart web server (IIS or apache)
Reference:
This could be SSL cert issue. Here is the solution:
Reference:
Doc: https://github.com/sendgrid/sendgrid-php
Complete example:
https://github.com/sendgrid/sendgrid-php/blob/master/USE_CASES.md#attachments
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
public function send($subject, $msg, $contact, $attachment=null){ $from = new SendGrid\Email($this->sender['name'], $this->sender['email']); $subject = $subject; $to = new SendGrid\Email($contact['name'], $contact['email']); $content = new SendGrid\Content("text/html", $msg); $mail = new SendGrid\Mail($from, $subject, $to, $content); if($attachment != false){ $att = $this->process_attachment($attachment); $mail->addAttachment($att); } $apiKey = $this->sg_key; $sg = new \SendGrid($apiKey); $response = $sg->client->mail()->send()->post($mail); if($response->statusCode() == 202){ return true; }else{ $this->err = '寄送Email失敗: ' . $contact['email']; return false; } echo '<prev>'; echo $response->statusCode(); print_r($response->headers()); echo $response->body(); echo '</prev>'; } public function process_attachment($file){ $file_encoded = base64_encode(file_get_contents($file)); $attachment = new SendGrid\Attachment(); $attachment->setContent($file_encoded); $attachment->setType("application/pdf"); $attachment->setDisposition("attachment"); $attachment->setFilename("order.pdf"); return $attachment; } |