0
첨부 파일이있는 PHP 이메일을 보내는 데 문제가 있습니다. 메일이 전송 된 메시지를 볼 수 있지만 메일은 전송되지만 첨부 파일은 없습니다. 나는 진짜 문제를 안다. 이것은 내 코드입니다. User.xlsx 파일을 루트 디렉터리에 저장했습니다. 이 문제를 해결하도록 도와주세요. 감사합니다첨부 파일이있는 PHP 전자 메일
$to = "[email protected]";
$subject="attachement";
$mail_msg="message with attach";
$filename="User.xlsx"; // Attachement file in root directory
$contentType="application/zip"; // Not sure about what to put here
$pathToFilename="./";
$random_hash = md5(date('r', time()));
$headers = "From: [email protected]\r\nReply-To: ".$to;
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$attachment = chunk_split(base64_encode(file_get_contents($pathToFilename)));
ob_start();
echo "
--PHP-mixed-$random_hash
Content-Type: multipart/alternative; boundary=\"PHP-alt-$random_hash\"
--PHP-alt-$random_hash
Content-Type: text/plain; charset=\"utf-8\"
Content-Transfer-Encoding: 7bit
$mail_msg
--PHP-alt-$random_hash--
--PHP-mixed-$random_hash
Content-Type: $contentType; name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
--PHP-mixed-$random_hash--
";
$message = ob_get_clean();
// $fh=fopen('log.txt','w');
// fwrite($fh,$message);
$mail_sent = @mail($to, $subject, $message, $headers);
echo $mail_sent ? "Mail sent" : "Mail failed";
수동 mime 구성으로 문제를 파악하려면 그렇게하십시오. 여기에서 수백 가지 다른 복제본을 연구하십시오. 그러나 다른 사람들에게 디버깅을 요청하지 마십시오. PHPMailer와 SwiftMailer는 어딘가에서 복사 한 코드를 사용하지 않고도 첨부 파일을 보낼 수있는 쉬운 메일을 허용합니다. – mario