【发布时间】:2013-07-16 12:47:39
【问题描述】:
我创建了一个就业申请,允许申请人上传 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);
?>
【问题讨论】:
-
sendgrid 端好像有个bug,你试过他们的支持吗?