php - Sendgrid will only send utf-8 attachments -


i've created employment application allows applicants upload resume in pdf, doc, or docx extensions. email information , resume human resources using sendgrid.

i've found through testing when sending email receive error:

parameter attachment[resume.pdf] not utf8

how can fix issues, should encode every file uploaded utf-8 before attaching email? create issues or severally modify users uploaded resume?

here php curl code use send via sendgrid api: (note: have use rest api, smtp not configured on clients web server)

    <?php          $mail['from'] = 'humanresources@email.org';                     $mail['fromname'] = 'human resources';                     $mail['to'] = 'person@email.com';                        $mail['subject'] = character_limiter('employment: '. $application['position'], 50);                      $mail['html'] = '<p><strong>name:</strong> '.$application['firstname'].' '.$application['lastname'].'</p>';                     $mail['html'] .= '<p><strong>position:</strong> '.$application['position'].'</p>';                     $mail['html'] .= '<p><strong>date:</strong> '.mdate('%m/%d/%y %g:%i %a', $application['timestamp_saved']).'</p>';                     $mail['html'] .= '<p><strong>email:</strong> '.$application['email'].'</p>';                       $mail['files['.$application['pdf'].']'] = '@saved_applications/'. $application['pdf'];                        //sendgrid credientals                     $mail['api_user']  = 'sendgrid_user';                     $mail['api_key']   = 'sendgrid_pass';                      print_r($mail);                      // generate curl request                     $session = curl_init('https://sendgrid.com/api/mail.send.json');                     curl_setopt ($session, curlopt_post, true);                     curl_setopt ($session, curlopt_postfields, $mail);                     curl_setopt($session, curlopt_header, false);                     curl_setopt($session, curlopt_returntransfer, true);                      // obtain response                     $response = curl_exec($session);                     curl_close($session);                      // print out                     $output = json_decode($response, true);                      print_r($output);  ?> 

the code have should work (and worked when tested it).

you may want use php library, rather flat curl. you'll able send attachments, web web api doing following:

<?php     $sendgrid = new sendgrid('username', 'password');     $mail = new sendgrid\mail();     $mail->     addto('humanresources@email.org')->     ...     addattachment('saved_applications/'. $application['pdf']);     $sendgrid->web->send($mail); ?> 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -