I'm making PHP script, that import some data from mysql database and send it via email in attachment. But there is one issue - in future there is possibility, that data will be sensitive. So I need to set password to attachment.
I'm using phpmailer method addStringAttachment
.
Some code:
<?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';
}
I hade some issues with UTF-8 chars, so I have to use UTF8 BOM. Can you give me some advice/tip, how to set attachment secuirty level at minimum? It does'nt metter how it will be encrypted - but it has to be. Give me a rod, please.