Created
September 27, 2012 13:13
-
-
Save feisuzhu/3793912 to your computer and use it in GitHub Desktop.
PHP: accept form and send as mail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$str = ''; | |
foreach($_POST as $k => $v) { | |
if(is_array($v)) { | |
$v = implode(', ', $v); | |
} | |
$str .= "$k: $v\n"; | |
} | |
$rnd = md5(time() + 'haha'); | |
$headers = <<<EENNDD | |
MIME-Version: 1.0 | |
Content-type: multipart/mixed; boundary="$rnd"; | |
EENNDD; | |
$message = <<<EENNDD | |
--$rnd | |
Content-Type: text/plain; charset=utf-8 | |
$str | |
EENNDD; | |
foreach($_FILES as $k => $f) { | |
if($f['error']) continue; | |
$fn = $f['name']; | |
$type = $f['type']; | |
$content = chunk_split(base64_encode(file_get_contents($f['tmp_name']))); | |
$message .= <<<EENNDD | |
--$rnd | |
Content-Type: $type; name="$fn" | |
Content-Transfer-Encoding: base64 | |
Content-Disposition: attachment | |
$content | |
EENNDD; | |
} | |
$message .= "--$rnd--"; | |
if(isset($_POST['姓名'])) { | |
$tail = ':' . $_POST['姓名']; | |
} else { | |
$tail = ''; | |
} | |
mail('[email protected]', '客户信息' . $tail, $message, $headers); | |
?> | |
<script type="text/javascript"> | |
alert("您的信息已经收到!我们会尽快联系您!"); | |
window.location.href = 'index.html'; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment