0
데이터베이스를 백업하고 zip 파일을 전자 메일로 보내려고합니다. 다음 코드는 zip을 첨부하지 않는다는 점을 제외하고는 잘 작동합니다. 메일과 모든 것이 잘 작동하고 zip 파일이 생성되었지만 첨부 할 수 없습니다.PHP 메일에 첨부 파일 추가하기
$today = date("d/m/Y");
$to = 'Chris P <[email protected]*****.co.uk>';
$subject = 'Back Up File - '.$today;
$headers = 'From: Backup <[email protected]******.co.uk>' . "\r\n" .
$headers.= 'Reply-To: ****** (Chris) <[email protected]******.co.uk>' . "\r\n" .
$headers.= "X-Mailer: PHP/" . phpversion()."\r\n";
$headers.= "MIME-Version: 1.0" . "\r\n";
$headers.= "Content-type: text/html; charset=iso-8859-1 \r\n";
$random_hash = md5(date('r', time()));
$attachment = chunk_split(base64_encode(file_get_contents($fileName)));
ob_start(); //Turn on output buffering
$message2 = "<font face='verdana' size='-2'>Hey Chris,<p>";
$message2 .= "Here is the back up of the database, taken on the <strong>$today.</strong>\n\n";
$message2 .= "<p>The archive has the name of: <strong>$fileName</strong> and it's file-size is <strong>$fileSize.</strong>\n\n";
$message2 .= "Please find the file attatched.\n\n";
$message2 .= "<p>****** BackUp Generator ";
$message2 .= "--PHP-mixed- $random_hash;";
$message2 .= "Content-Type: application/zip; name=\"$filename\"";
$message2 .= "Content-Transfer-Encoding: base64";
$message2 .= "Content-Disposition: attachment";
$message2 .= $attachment;
$message2 .= "--PHP-mixed-<?php echo $random_hash; ?>--";
이미 PHP 코드 안에 ''태그를 사용할 수 없습니다. – JJJ
여기에서 필요한 것을 찾을 수 있습니다 ... http : //webcheatsheet.com/php/send_email_text_html_attachment.php... 참조 용 – sanj
모든 코드를 버리고 phpMailer 클래스를 다운로드하십시오. 많은 시간과 노력을 아끼지 마십시오. – Spudley