Skip to content

Instantly share code, notes, and snippets.

@exileed
Forked from webstoun/index.html
Last active August 29, 2018 13:25
Show Gist options
  • Save exileed/61b32de5cdbff2eafd998c8f2453b5dd to your computer and use it in GitHub Desktop.
Save exileed/61b32de5cdbff2eafd998c8f2453b5dd to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>uniMail</title>
</head>
<body>
<form action="mail.php" method="POST">
<!-- Hidden Required Fields -->
<input type="hidden" name="project_name" value="Site Name">
<input type="hidden" name="admin_email" value="[email protected]">
<input type="hidden" name="form_subject" value="Form Subject">
<!-- END Hidden Required Fields -->
<input type="text" name="Name" placeholder="You name..." required><br>
<input type="text" name="Phone" placeholder="You phone..." required><br>
<input type="file" name="File" required><br>
<button id="button">Send</button>
</form>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
</body>
</html>
<?php
$method = $_SERVER[ 'REQUEST_METHOD' ];
//Script Foreach
$c = true;
if ($method === 'POST') {
$project_name = trim($_POST[ "project_name" ]);
$admin_email = trim($_POST[ "admin_email" ]);
$form_subject = trim($_POST[ "form_subject" ]);
foreach ($_POST as $key => $value) {
if ($value !== "" && $key !== "project_name" && $key !== "admin_email" && $key !== "form_subject") {
$message .= "
" . (($c = ! $c) ? '<tr>' : '<tr style="background-color: #f8f8f8;">') . "
<td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>
<td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>
</tr>
";
}
}
$f = $_FILES['file']['tmp_name'];
$filename = $_FILES['file']['name'];
$file = fopen($f,'rb');
$data = fread($file,filesize($f));
$message .= "--" . md5(time()) . "--";
$message .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"" . PHP_EOL;
$message .= "Content-Transfer-Encoding: base64" . PHP_EOL;
$message .= "Content-Disposition: attachment" . PHP_EOL;
$message .= $data . PHP_EOL;
$message .= "--" . md5(time()) . "--";
} elseif ($method === 'GET') {
$project_name = trim($_GET[ "project_name" ]);
$admin_email = trim($_GET[ "admin_email" ]);
$form_subject = trim($_GET[ "form_subject" ]);
foreach ($_GET as $key => $value) {
if ($value != "" && $key !== "project_name" && $key !== "admin_email" && $key !== "form_subject") {
$message .= "
" . (($c = ! $c) ? '<tr>' : '<tr style="background-color: #f8f8f8;">') . "
<td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>
<td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>
</tr>
";
}
}
}
$message = "<table style='width: 100%;'>$message</table>";
function adopt($text)
{
return '=?UTF-8?B?' . base64_encode($text) . '?=';
}
$headers = "MIME-Version: 1.0" . PHP_EOL .
"Content-Type: text/html; charset=utf-8" . PHP_EOL .
'From: ' . adopt($project_name) . ' <' . $admin_email . '>' . PHP_EOL .
'Reply-To: ' . $admin_email . '' . PHP_EOL;
mail($admin_email, adopt($form_subject), $message, $headers);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment