2
助けてください。私はこれが基本的なものだとわかりますが、なぜ私のPDFが空であるのか混乱しています。私はPDF添付ファイルで電子メールを受信していますが、空のPDFファイルであるため、理由を把握できません。私はここで他の同様の質問を見てきましたが、それらが役に立つとは思わなかった。私はフレームワークや依存関係を使用したくない。ご協力ありがとうございました。私はこれを15分以内に行うことを期待していましたが、このバグは私を元に戻しました。ディレクトリ内のPDFをループしてメールを送信するPHP
$dir = "scanned_files";
function is_dir_empty($dir) {
if(!is_readable($dir)){
return NULL;
}
$handle = opendir($dir);
while(false !== ($entry = readdir($handle))){
if ($entry != "." && $entry != "..") {
return FALSE;
}
}
return TRUE;
}
if (is_dir_empty($dir)) {
echo "the folder is empty";
}else{
$files = array_diff(scandir($dir), array('.', '..', '.DS_Store'));
foreach($files as $filename){
$content = file_get_contents($dir . "/" . $filename);
$content = chunk_split(base64_encode($content));
$email = "[email protected]";
$subject = "Scanned document from the road!";
$separator = md5(time());
$headers = "From: [email protected]" . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: multipart/mixed; boundary=\"" . $separator . "\"" . "\r\n";
$headers .= "Content-Transfer-Encoding: 7bit" . "\r\n";
$msg = "--" . $separator . "\r\n";
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . "\r\n";
$msg .= "Content-Transfer-Encoding: 8bit" . "\r\n";
$msg .= "Your file has arrived." . "\r\n";
$msg .= "--" . $separator . "\r\n";
$msg .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"" . "\r\n";
$msg .= "Content-Transfer-Encoding: base64" . "\r\n";
$msg .= "Content-Disposition: attachment" . "\r\n";
$msg .= $content . "\r\n";
$msg .= "--" . $separator . "--";
mail($email, $subject, $msg, $headers);
echo PHP_EOL . "Mail sent. Filename: " . $filename . PHP_EOL;
}
}
"フレームワークや依存関係を使用したくありません。"私はこれがなぜ15分以上かかったのかとたくさん関係があり、今後あなたのコードが失敗する可能性が高くなると思います。これ以上の時間を無駄にしないようにして、その時間をより生産的に投資することを検討してください。[学習方法](http://swiftmailer.org/docs/messages.html#attaching-files)(非常に簡単に)パーティーライブラリー。 – deefour
私はそれを考慮しました。しかし、私はこのタイプのアドバイスについてこの質問を投稿しませんでした。私はなぜ私のPDFが空であるか/私が紛失していることを知りたいだけです。 – pascalallen