phpmailerで日本語の添付ファイルを複数送りたいのですがどうすればいいでしょうか?
英数文字のファイル名の添付は問題なく送れます。
日本語ファイルは1つのファイルでもNGになります。最終的には複数の日本語ファイルを送りたいです。
画面遷移としては
formで各種項目を入力、ファイルを指定する(この時に複数ファイルを選択す方法をしりたいです。)
→入力情報を表示して確認する。問題なければ送信ボタンをクリック
→送信
しています。
日本語ファイルの場合は下記のエラーとなります。
1ファイルだけでもエラーになります。
var_dump()の結果は Could not access file: ../photo/photo_img/�ق��ق��ق�.txt object(PHPMailer\PHPMailer\Exception)#4 (7) { ["message":protected]=> string(70) "Could not access file: ../photo/photo_img/�ق��ق��ق�.txt" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(1) ["file":protected]=> string(82) "/virtual/digilabo/public_html/digi-labo.net/mff/PHPMailer-master/src/PHPMailer.php" ["line":protected]=> int(2816) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(82) "/virtual/digilabo/public_html/digi-labo.net/mff/PHPMailer-master/mail_send_pmm.php" ["line"]=> int(89) ["function"]=> string(13) "addAttachment" ["class"]=> string(29) "PHPMailer\PHPMailer\PHPMailer" ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> string(47) "../photo/photo_img/�ق��ق��ق�.txt" [1]=> string(22) "ほげほげほげ.txt" } } [1]=> array(4) { ["file"]=> string(75) "/virtual/digilabo/public_html/digi-labo.net/mff/v6/info/pm_info_send_v6.php" ["line"]=> int(196) ["args"]=> array(1) { [0]=> string(82) "/virtual/digilabo/public_html/digi-labo.net/mff/PHPMailer-master/mail_send_pmm.php" } ["function"]=> string(7) "include" } } ["previous":"Exception":private]=> NULL }
宜しくお願い致します。
input_form.php ///入力フォーム <form action="send_check.php" method="post" enctype="multipart/form-data"> <input type="file"name="file_name" multiple> </form>
send_check.php ///内容チェック $file_name = $_FILES['file_name']['name']; $file_path = $_FILES['file_name']['tmp_name']; $file_mime = $_FILES['file_name']['type']; echo 'file name'.$file_name; echo 'file_path'.$file_path; ///$file_pathは右のように表示されます。 file_path:/export/tmp/phpawDB94 <form action="mail_send.php" method="post"> <input type="hidden" name="file_name" value="<?=$file_name ?>"> <input type="hidden" name="file_path" value="<?=$file_path ?>"> <input type="hidden" name="file_mime" value="<?=$file_mime ?>"> </form>
mail_send.php ///送信 use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; require 'src/Exception.php'; require 'src/PHPMailer.php'; require 'src/SMTP.php'; $file_name = $_POST['file_name']; $file_path = $_POST['file_path']; $mail = new PHPMailer(true); // Passing `true` enables exceptions try { //Server settings $mail->SMTPDebug = 2; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'hogeserver.jp'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->CharSet = 'utf-8'; //文字セットこれでOK $mail->Username = 'hogename'; // SMTP username $mail->Password = 'pass'; // SMTP password $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 587; // TCP port to connect to (ssl:465) //Recipients $mail->setFrom('hogename','hogeMail'); //必ずしも送信アドレスと同一でなくても送れる $mail->addAddress($send_to,$to_name); // Add a recipient $mail->addAddress($send_to); // Name is optional $mail->addReplyTo('hoge_error@hoge.xxx', 'hoge_error'); //エラーとして戻ってくる先 //Attachments if($filename !== ""){ $mail->addAttachment($fid_path,$filename); // 添付ファイルのパスと名称 } //Content $mail->isHTML(false); // HTMLメールのときは「true」、textメールのときは「false」 $mail->Subject = mb_convert_encoding($subject_text, "UTF-8", "AUTO"); $mail->Body = $body_text; //textメール $mail->send(); echo 'Message has been sent'; } catch (Exception $e) { echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo; }
