我创建了一个就业申请,允许申请人以 pdf、doc 或 docx 扩展名上传他们的简历。然后,我使用 Sendgrid 将他们的信息和简历通过电子邮件发送给人力资源部。
我通过测试发现在发送邮件时收到错误:
参数附件[resume.pdf]不是utf8
我该如何解决这个问题,我应该在将上传到 utf-8 的每个文件附加到电子邮件之前对其进行编码吗?这会产生任何问题或单独修改用户上传的简历吗?
这是我用来通过 SendGrid API 发送的 PHP Curl 代码:(注意:我必须使用 REST API,客户端 Web 服务器上未配置 SMTP)
<?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 everything out
$output = json_decode($response, TRUE);
print_r($output);
?>