이미지를 base64로 인코딩하려고 시도했지만 php mail()을 사용하여 이메일 첨부 파일로 보냈지 만 이메일에 base64 텍스트가 모두 표시됩니다. . 다음은 내가 사용하고있는 것입니다 :PHP : base64 이미지를 첨부 한 메일()이 텍스트로 나옴
$boundary1 = 'bound1';
$boundary2 = 'bound2';
$to = '[email protected]';
$subject = 'Test Image attachment';
$headers = 'From: "Me" <[email protected]>'."\r\n";
//add boundary string and mime type specification
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary1\"";
//define the body of the message.
$message = 'Content-Type: image/png; name="'.$file_name.'"'."\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-Disposition: inline; filename=\"$file_name\"\n\n";
$message .= base64_encode_image("signature_files/".$file_name, 'png')."\n";
$message .= "--" . $boundary2 . "\n";
//send the email
mail($to, $subject, $message, $headers);
// Function to encode an image
function base64_encode_image($filename=string,$filetype=string) {
if ($filename) {
$imgbinary = fread(fopen($filename, "r"), filesize($filename));
return 'data:image/' . $filetype . ';base64,' . chunk_split(base64_encode($imgbinary), 64, "\n");
}
}
이 코드에 문제가있는 사람이 있습니까? 왜 내가 이메일을받을 때 RAW 텍스트 만 보는지 정말로 확신하지 못한다.
를 사용합니다. [Swiftmailer] (http://swiftmailer.org) 또는 [PHPMailer] (http://phpmailer.worxware.com)를 사용하고이 모든 번거 로움을 덜어줍니다. 그들은 모두 첨부 파일과 인라인 이미지를 쉽게 처리합니다. –
@Marc - 좋은 생각이지만이 프로젝트에는 사치가 없습니다. –