0
我正在做PHP脚本,从mysql数据库中导入一些数据,并通过附件中的电子邮件发送它。但是有一个问题 - 未来有可能,数据会很敏感。所以我需要设置密码来附件。PHPMailer密码保护附件
我正在使用phpmailer方法addStringAttachment
。
一些代码:
<?php
require 'PHPMailerAutoload.php';
$con = new mysqli("x", "x", "x", "x");
$utf1 = "SET NAMES utf8";
$utf2 = "SET character_set_results = 'utf8',
character_set_client = 'utf8',
character_set_connection = 'utf8',
character_set_database = 'utf8',
character_set_server = 'utf8'";
$con->query($utf1);
$con->query($utf2);
$output ='';
$result = $con->query("select * from xxx WHERE DATE(entry_date) BETWEEN (DATE(CURDATE() - INTERVAL 3 DAY)) AND (DATE(CURDATE() - INTERVAL 1 DAY))");
$columns_total = $con->field_count;
// Get The Field Name
for ($i = 0; $i < $columns_total; $i++) {
$heading = mysqli_fetch_field_direct($result, $i)->name;
$output .= '"'.$heading.'";';
}
$output .="\n";
// Get Records from the table
while ($row = $result->fetch_array()) {
for ($i = 0; $i < $columns_total; $i++) {
$output .='"'.$row["$i"].'";';
}
$output .="\n";
}
$filename = "myFile.xls";
header('Content-Encoding: UTF-8');
$bomoutput = "\xEF\xBB\xBF" . $output;
$con->close();
的PHPMailer:
$mail = new PHPMailer;
[...]
$mail->From = 'xx';
$mail->FromName = 'xx';
$mail->addAddress('xx'); // Add a recipient
$mail->addStringAttachment($bomoutput, $filename);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
我哈德与UTF8字符的一些问题,所以我必须使用UTF8 BOM。你能给我一些建议/提示,如何设置附件安全级别至少?它不会考虑如何加密 - 但它必须是。请给我一根杖。
'WHERE ..... AND protection ='set_password'' –