2013-10-06 47 views
-1

我的表單允許用戶通過我的電子郵件向我發送消息,但我希望當用戶填寫表單並選擇文件時,文件會上傳到服務器,該消息被髮送給我。我沒有做消息部分,但我無法上傳文件。這裏是我的代碼: 索引頁:發送郵件並上傳PHP中的文件

<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 = "[email protected]"; 
$subject = "New Message!!"; 
$mailheader = "From: $title \r\n"; 
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); 
header("Location: www.mythankyoupage.com"); 
die(); 
?> 
+0

@David非常感謝你,那正是我一直在尋找的! – Ayoub

回答