0

我的表单允许用户在我的电子邮件中向我发送消息,但我希望当用户填写表单并选择文件时,文件会上传到服务器并将消息发送给我。我确实做了消息部分,但我无法上传文件。这是我的代码:索引页:

<form action="mail.php" method="post" enctype='multipart/form-data'>
<input type="text" class="feedback-input" id="firstname" name="firstname"       placeholder="First Name" size="30" required="">
<br/>
<input type="text" class="feedback-input" id="lastname" name="lastname"     placeholder="Last Name" size="30" required="">
<br/>
<input type="email" class="feedback-input" id="title" name="title" placeholder="E-mail"       size="30" required="">
<br/>
<textarea name="message" class="feedback-input" placeholder="What can I help you with?"   style="height: 150px;" required=""></textarea><br/>
<br/>

<input type="file" name="file" id="file" placeholder=" " tabindex="1" required/><br/>
<input type="submit" name="submit" id="Submit" value="Send">

这是 mail.php 文件:

<?php
$firstname = $_POST['firstname'];
$title = $_POST['title'];
$lastname = $_POST['lastname'];
$message = $_POST['message'];
$ip = $_SERVER['REMOTE_ADDR'];
$formcontent=" From: $firstname $lastname \n Email Address: $title \n IP: $ip \n\n                         Description : $message";
$recipient = "myemail@yahoo.com";
$subject = "New Message!!";
$mailheader = "From: $title \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header("Location: www.mythankyoupage.com");
die();
?>
4

1 回答 1

0

我认为您的文件上传应该基于此 http://www.w3schools.com/php/php_file_upload.asp 如果您卡在某个地方,请发表评论,我很乐意提供帮助!:)

于 2013-10-06T16:48:37.637 回答