我们正尝试将电子邮件发送给具有PDF附件的多个用户。附件PDF是通过kartik \ mpdf \ Pdf生成的。
我们遵循的步骤
'pdf' => [
'class' => Pdf::classname(),
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_STRING,
]
==========================
use Aws\Ses\SesClient;
//Fetch all records whose mail_send is 0 and in_queue is 0
$email_model = new MailQueue();
$mail_queue_data = // select query to get Email IDs, email content etc from mail queue table;
foreach($mail_queue_data as $result)
{
try {
// Create SES client Instance
$gaws_ses_client = SesClient::factory(array(
'version' => 'latest',
'region' => 'us-east-1',
'credentials' => [
'key' => 'YOUR_KEY',
'secret' => 'YOUR_SECRET_KEY',
]
));
// Set SES linked user email
$my_from_address = 'this_is_test@demo.com';
$my_string_to_addresses = $result['to_email'];
$my_array_to_adresses = [$my_string_to_addresses];
$my_subject = isset($result['subject']) ? $result['subject'] : '';
$my_html_body = isset($result['email_html']) ? $result['email_html'] : '';
// Set mail message
$my_message = "";
$my_message .= "MIME-Version: 1.0\n";
$my_message .= "To: ".$my_string_to_addresses."\n";
$my_message .= "From:".$my_from_address."\n";
$my_message .= "Subject:".$my_subject."\n";
$my_separator = md5(time());
$my_separator_multipart = md5($my_subject . time());
// Set headers
$my_message .= "Content-Type: multipart/mixed; boundary=\"".$my_separator_multipart."\"\n";
$my_message .= "\n--".$my_separator_multipart."\n";
$my_message .= "Content-Type: multipart/alternative; boundary=\"".$my_separator."\"\n";
$my_message .= "\n--".$my_separator."\n";
$my_message .= "Content-Type: text/html; charset=\"UTF-8\"\n";
$my_message .= "\n".$my_html_body."\n";
$my_message .= "\n--".$my_separator."--\n";
$content = $my_html_body;
$pdf = Yii::$app->pdf;
$pdf->cssFile = '@backend/web/css/externalcss_file_name.css';
$pdf->content = $content;
$raw_data = $pdf->render();
$my_file_name = 'attachment.pdf';
$my_data_attached_file = chunk_split(base64_encode($raw_data));
$file_info = new \finfo(FILEINFO_MIME_TYPE);
$my_file_mime_type = $file_info->buffer($raw_data);
$my_message .= "--".$my_separator_multipart."\n";
$my_message .= "Content-Type: ".$my_file_mime_type."; name=\"".$my_file_name."\"\n";
$my_message .= "Content-Disposition: attachment; filename=\"".$my_file_name."\"\n";
$my_message .= "Content-Transfer-Encoding: base64\n\n";
$my_message .= $my_data_attached_file."\n";
$my_message .= "--".$my_separator_multipart."--";
$my_array_ses = [
'Source' => $my_from_address,
'Destinations' => $my_array_to_adresses,
'RawMessage' => [
'Data' => $my_message
]
];
$my_api_result = $gaws_ses_client->sendRawEmail($my_array_ses);
//view sample output
echo "\n<BR>SES Result:<BR>\n";
echo "Message ID : ".$my_api_result['MessageId']."<BR>\n";
print_r($my_api_result);
echo "<BR>\n";
} catch (Exception $my_obj_error) {
//An error happened and the email did not get sent
$my_error_info = $my_obj_error->getMessage();
echo "\n<BR>*** SES ERROR:<BR>\n";
print_r($my_error_info);
echo "<BR>\n";
$myfile = fopen("ses_send_error.txt", "w");
fwrite($myfile, $my_error_info);
fclose($myfile);
}
}
PHP公告– yii \ base \ ErrorException
未定义索引:数据
当PDF包含图像时,将生成该异常。如果我们生成没有图像的PDF,则它可以正常工作。那么如何解决这个问题呢?
答案 0 :(得分:0)
为了解决此问题,我建议如下将硬编码到电子邮件地址。确保添加真实的电子邮件地址。一旦工作,您就可以将my_string_to_addresses
格式化为这种格式。
$my_array_to_adresses = ['email1@domain.com', 'email2@domain.com'];