완성 된 전자 메일을 첨부 파일이있는 사용자에게 보내는 웹 응용 프로그램을 설정하려고합니다. 전자 메일을 HTML 형식과 텍스트 형식으로 모두 사용하여 모든 사용자가 자신의 메일 설정에 관계없이 볼 수 있도록하고 싶습니다. 나는 그것이 작동하도록하는 데 어려움을 겪고있다. 그래서 누군가 내 코드로 문제를 발견 할 수 있는지 궁금했다.HTML/텍스트 PHP를 사용하는 첨부 파일이 포함 된 전자 메일
내가 사용하는 코드는 다음과 같습니다. 이 템플릿은 다른 사이트의 템플릿으로 사용되었지만 읽는 방법을 많이 읽었으므로 어떻게 작동하는지 대략 이해했습니다. 불행히도, 문제를 해결하기위한 충분한 이해가 아닙니다!
$firstname = $_POST['firstname'];
$email = $_POST['email'];
//define the receiver of the email
$to = $email;
//define the subject of the email
$subject = "$firstname, thanks for using the One Minute Leveller";
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: The Xenon Group\r\nReply-To: [email protected]";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
//read the atachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks
$attachment = chunk_split(base64_encode(file_get_contents('Level3info.pdf')));
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
TEXT E-MAIL GOES HERE. ACTUAL CONTENT REMOVED
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<html><h1>HTML CONTENT GOES HERE. ACTUAL CONTENT REMOVED</h1></html>
--PHP-alt-<?php echo $random_hash; ?>--
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: application/pdf; name="Level3info.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
<?php echo $attachment; ?>
--PHP-mixed-<?php echo $random_hash; ?>--
<?php
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
mail($to, $subject, $message, $headers);
아무도 도와 줄 수 있습니까?! 당신이 당신의 헤더와 그 허용되지 않는 사이에 공백이 같은 http://pear.php.net/package/Mail/redirected
둘째 배 메일로 라이브러리를 사용 -
이렇게 PHP를 들락날락하지 말 것을 권합니다. 그것은 당신의 코드를 읽기가 어렵게 만든다. – Travesty3
이와 같은 작업에 기존 클래스를 사용하는 것이 좋습니다. http://pear.php.net/manual/en/package.mail.mail-mime.addattachment.php – powtac