提交表單後得到的郵件,但它去消息發送消息白黑屏。PHP提交表單後提交空白頁
我嘗試在提交表單後重新加載頁面,但出現錯誤。
<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$to = "[email protected]";
$subject = "E-mail with attachment";
$from = stripslashes($_POST['fromname']) . "<" . stripslashes($_POST['fromemail']) . ">" . "<" . stripslashes($_POST['designation']) . ">";
// generate a random string to be used as the boundary marker
$mime_boundary = "==Multipart_Boundary_x" . md5(mt_rand()) . "x";
// now we'll build the message headers
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
$message = "Canditade Resume";
// when we use it
$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";
// iterating each File type
print_r($_FILES);
foreach ($_FILES as $userfile) {
$tmp_name = $userfile['tmp_name'];
$type = $userfile['type'];
$name = $userfile['name'];
$size = $userfile['size'];
if (file_exists($tmp_name)) {
if (is_uploaded_file($tmp_name)) {
$file = fopen($tmp_name, 'rb');
$data = fread($file, filesize($tmp_name));
fclose($file);
$data = chunk_split(base64_encode($data));
}
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$tmp_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n";
}
}
// here's our closing mime boundary that indicates the last of the message
$message.="--{$mime_boundary}--\n";
// now we just send the message
if (@mail($to, $subject, $message, $headers))
echo "Message Sent";
else
echo "Failed to send";
} else {
?>
<form action="index.php" method="post" enctype="multipart/form-data" name="form1">
<label>Name</label>
<input type="text" name="fromname" class="input-block-level" style="width: 100%" required placeholder="Your First Name">
<label>Email Address</label>
<input type="text" style="width: 100%" class="input-block-level" required placeholder="Your email address" name="fromemail">
<label>Designation</label>
<input type="text" style="width: 100%" class="input-block-level" name="designation" required placeholder="Designation">
<label>Upload Your CV</label>
<input type="file" class="input-block-level" required placeholder="Upload Your CV" name="file1">
</div>
<input type="submit" name="Submit" value="Submit" class="btn btn-primary btn-large pull-left" onclick="javascript: form.action='index.php';">
</form>
<?php } ?>
請幫我
你想達到什麼目的?什麼是你沒有預料到的錯誤? – Cagy79
表單工作正常,提交後我想驗證表單,然後想要重新回到其他頁面 –
請用您現在的代碼更新您問題中的代碼。 – Cagy79