비슷한 질문이 여기에 보관되어있는 것 같습니다. (나는 많은 것을 살펴 봤습니다.) Google은 내 친구입니다. (검색하고 검색했습니다). 당신이 충분히 열심히 노력하고 있다고 생각하지 않는다면 이것을 downvote해라. 그러나 나는 단지 그 과정에서 머리를 감싸는 것처럼 보이지 않을 것이고, 확실히 도움을받을 수있다.PHP 문의 양식 첨부 파일 업로드 첨부 파일
파일 업로드 옵션을 추가하려는 간단한 PHP 문의 양식 (Seen Here)이 있으므로 클라이언트가 중요한 문서를 첨부하고 PHP 메일 기능을 사용하여 메일을 보낼 수 있습니다.
양식 자체는 정상적으로 작동하지만 첨부 파일을 업로드하고 서버에 일시적으로 저장하고 전자 메일의 일부로 보내는 코드를 얻지 못하는 것 같습니다. 여기에 내가 사용하고 코드입니다 : 나는 현재이 스크립트를 실행하면
<?php
if ($_POST['test'] != '') {
echo 'Unfortunately, by filling out the hidden field, you have been identified as a potential spambot and your message has been terminated.';
} else {
//Validate the name:
if (!empty($_POST['name'])) {
$name = $_POST['name'];
} else {
echo "You forgot to enter your name.<br>";
}
//Validate the phone:
if (!empty($_POST['phone'])) {
$phone = $_POST['phone'];
} else {
echo "You forgot to enter your phone number.<br>";
}
//Validate the e-mail:
if (!empty($_POST['email'])) {
$email = $_POST['email'];
} else {
echo "You forgot to enter your e-mail.<br>";
}
//Validate the message:
if (!empty($_POST['message'])) {
$message = $_POST['message'];
} else {
echo "You forgot to enter a message.";
}
if (!empty($_POST['name']) && !empty($_POST['phone']) && !empty($_POST['email']) && !empty($_POST['message'])) {
// Obtain file upload variables:
$attachment = $_FILES['attachment']['tmp_name'];
$attachment_type = $_FILES['attachment']['type'];
$attachment_name = $_FILES['attachment']['name'];
if (file($attachment)) {
// Read the file to be attached ('rb' = read binary):
$file = fopen($attachment,'rb');
$data = fread($file,filesize($attachment));
fclose($file);
// Generate a boundary string:
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment:
$headers = "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message:
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
// Base64 encode the file data:
$data = chunk_split(base64_encode($data));
// Add file attachment to the message:
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$attachment_type};\n" .
" name=\"{$attachment_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$attachment_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
$body = "$name\n$phone\n$email\n\n$message";
mail("*@*.com", "Starcrest Escrow, Inc. Website - Real Property Sale", $body, $headers);
header("Location: confirm.html");
}
}
?>
, 그것은 확인 페이지에 저를 전달는 있지만 전자 메일은 전혀 생성 될 나타납니다. 내가 도대체 뭘 잘못하고있는 겁니까? 모든 조언은 대단히 감사합니다! http://www.excellentwebworld.com/send-file-in-email-attachment-on-form-submit-using-php/
당신의 HTML 양식 입력이 URL에서 PHP 측과 작업을 일치하는지 확인하고이 해결 나타날 수 있습니다
서버 오류가 발생하고 있습니까? $ 데이터가 첨부 파일의 내용으로 채워져 있습니까? –
나는 HTML 형식의 정확한 스크립트를 가리키고 있지 않다는 것을 깨달았다. 이제 문제가 해결되어 모든 정보가 담긴 전자 메일을 보냅니다. 그러나 첨부 파일은 메시지의 맨 아래에 텍스트 데이터로 표시됩니다. 예를 들어, PDF 파일은 "JVBERi0xLjMKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFIvRmlsdGVyIC9GbGF0ZURlY29k"의 줄이됩니다. 어떤 생각인지 알 겠어? 감사! – 712Jefferson
예! –