在现有的Bootstrap表单中添加文件上传功能

时间:2016-08-02 19:57:31

标签: php file-upload contact-form

我的网站在这里:vectormaid.com

我使用了一个我喜欢的引导模板,现有的联系表单只需要我的电子邮件才能工作。我想在此表单中添加文件上传。我已经按照自己的喜好设计了按钮,它运行良好(你可以选择多个文件,它们显示为在表单中被选中)。

如何添加php功能以使文件上传部分正常工作?其他所有内容都在电子邮件中发送,所以我知道表单正在减去文件上传。

这是我的php表单:

<?php
// Check for empty fields
if(empty($_POST['name'])      ||
   empty($_POST['email'])     ||
   empty($_POST['phone'])     ||
   empty($_POST['message'])   ||
   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
   {
   echo "No arguments Provided!";
   return false;
   }

$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$message = strip_tags(htmlspecialchars($_POST['message']));

// Create the email and send the message
$to = 'artwork@vectormaid.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form:  $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: noreply@vectormaid.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
$headers .= "Reply-To: $email_address";   
mail($to,$email_subject,$email_body,$headers);
return true;         
?>

0 个答案:

没有答案