php - PHPMailer password-protected attachment -
i'm making php script, import data mysql database , send via email in attachment. there 1 issue - in future there possibility, data sensitive. need set password 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 * xxx date( entry_date ) between ( date( curdate( ) - interval 3 day )) , ( date( curdate( ) - interval 1 day ) )"); $columns_total = $con->field_count; // field name ($i = 0; $i < $columns_total; $i++) { $heading = mysqli_fetch_field_direct($result, $i)->name; $output .= '"'.$heading.'";'; } $output .="\n"; // records table while ($row = $result->fetch_array()) { ($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 recipient $mail->addstringattachment($bomoutput, $filename); $mail->subject = 'here subject'; $mail->body = 'this html message body <b>in bold!</b>'; $mail->altbody = 'this body in plain text non-html mail clients'; if(!$mail->send()) { echo 'message not sent.'; echo 'mailer error: ' . $mail->errorinfo; } else { echo 'message has been sent'; }
i hade issues utf-8 chars, have use utf8 bom. can give me advice/tip, how set attachment secuirty level @ minimum? does'nt metter how encrypted - has be. give me rod, please.
this doesn't have phpmailer or mysql - store or send whatever like, , if want encrypt it, that's you.
php has several functions allow encrypt strings - making usable bit more involved if want sure recipient able decrypt - zip files easiest solution.
this question has suggestions.
Comments
Post a Comment