我正在处理一个完美运行的联系表单,但我希望有一个图像上传功能,以便将图像与邮件一起发送,作为我指定的电子邮件的附件。这是我的代码:
<form method="post" action="contact.php">
<label>Name</label>
<input name="name" type="text" placeholder="">
<label>Email</label>
<input name="email" type="email" placeholder="">
<label>message</label>
<textarea name="message" placeholder=""></textarea>
<label>How much is 2+2? (Anti-spam)</label>
<input name="human" type="number" placeholder=""><br>
<input id="submit" name="submit" type="submit" value="Send message!" class="button_verde"><br><br>
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'Website';
$to = 'mail@mail.com';
$subject = 'New message';
$human = $_POST['human'];
$headers = "MIME-Version: 1.0" . PHP_EOL;
$headers .= "From: $from <$email> ". PHP_EOL;
$headers .= "Content-type: text/html;charset=UTF-8 ". PHP_EOL;
$name = str_replace( '[at]','@', $name);
$message = str_replace( '[at]','@', $message);
$body = "<strong>Från:</strong> $name\n <br><strong>E-post:</strong> $email\n <br><strong>Meddelandet:</strong>\n <br>$message";
if ($_POST['submit']) {
if ($name != '' && filter_var($email, FILTER_VALIDATE_EMAIL)) {
if ($human == '4') {
if (mail ($to, $subject, $body, $headers)) {
echo '<div data-alert class="alert-box success radius">
Message sent!<a href="#" class="close">×</a>
</div>';
} else {
echo '<div data-alert class="alert-box warning round">
Try again!<a href="#" class="close">×</a>
</div>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<div data-alert class="alert-box warning round">
Wrong answer!<a href="#" class="close">×</a>
</div>';
}
} else {
echo '<div data-alert class="alert-box warning round">
Missing obligatory fields!<a href="#" class="close">×</a>
</div>';
}
}
?>
</form>
我的问题是,如何将图片上传添加到此表单?