2012-10-13 114 views
0

我是新來的PHP。我從互聯網上找到了一個正在正常工作的腳本。但是,當我將附件腳本添加到此文件時,它不再正常工作。PHP郵件附件不起作用

爲了使其正常工作,我應該做些什麼改變?

否則請使更改正常工作。

<html> 
<?php 
if($_GET['name']== '' || $_GET['email']=='' || $_GET['Message']=='') 
{ 
?> 

<form action="check2.php" method="get" name="frmPhone"> 
<fieldset> 
<legend style="color:#000">Contact </legend> 
<table width="100%"> 
<tr> 
<td width="29%"> 
<label for="name"  <?php if(isset($_GET['Submit']) && $_GET['name']=='') echo "style='color:red'";?>>Name* </label>  </td> <td width="71%"> 
<input id="name" name="name" type="text" style="width:50%" value=" <?php echo $_GET['name'];?>"/> </td> </tr> <tr> <td> 

<label for=" email"  <?php if(isset($_GET['Submit']) && $_GET['email']=='') echo "style='color:red'";?>>Email* </label>  </td> <td> 
<input id="email" name="email" type="text" style="width:50%" value=" <?php echo $_GET['email'];?>"/>  </td> </tr> 
</table> 
</fieldset> 
<fieldset> 
<legend style="color:#000">Inquiry </legend> 
<table width="100%"> 
<tr> <td width="41%" valign="top"> 

<label for="Message"  <?php if(isset($_GET['Submit']) && $_GET['Message']=='') echo "style='color:red'";?>>Message* </label>  </td> <td width="59%"> <textarea name="Message" rows="5" style="width:90%" id="Message"> <?php echo $_GET['Message'];?> </textarea> </td> 
    </tr> 
    <tr> 
    <td> </td> 
    <td align="right">&nbsp; </td> 
    </table> 
</fieldset> 

</form> 
<td> 
<li id="li_8" > 
     <label class="description"  <?php if(isset($_GET['Submit']) && $_GET['uploaded_file']=='') echo "style='color:red'"; ?> for="element_8">Upload your logo  </label> 
     <div> 
     <input name="uploaded_file" class="element file" type="file"/> 
     </div>  <p class="guidelines" id="guide_8"> <small>Upload your logo here. there is a max of 1 mb </small> </p> 
    </li>   <li id="li_9" > 
     <label class="description"  <?php if(isset($_GET['Submit']) && $_GET['uploaded_file']=='') echo "style='color:red'";?> for="element_9">Upload foto 1  </label> 
     <div> 
     <input name="uploaded_file" class="element file" type="file"/> 
     </div>  <p class="guidelines" id="guide_9"> <small>Upload your logo here. there is a max of 1 mb </small> </p> 
     </li> <input name="Submit" type="submit" value="Submit" /> 
</form> </td> 
    </tr> 

<?php 
} 
else 
{ 
$to  = '[email protected]'; 
$subject = 'Customer Information'; 
$message = ' 
Name: '.$_GET['name'].' 
Email Address: '.$_GET['email'].' 
Message: '.$_GET['Message']; 
$uploads_dir = '/uploads'; 
foreach ($_FILES["uploaded_file"]["error"] as $key => $error) { 
if ($error == UPLOAD_ERR_OK) { 
    $tmp_name = $_FILES["uploaded_file"]["tmp_name"][$key]; 
    $name = $_FILES["uploaded_file"]["name"][$key]; 
    move_uploaded_file($tmp_name, "$uploads_dir/$name"); 
} 
} 

$headers = 'From:'.$_GET['email']; 

mail($to, $subject, $message, $headers, $uploads_dir); 
$connection=mysql_connect("your host", "id", "pass") or die(mysql_error()); 
mysql_select_db("id") or die(mysql_error()); 
$query = mysql_query("INSERT INTO `feedback` ( `name` , `email` , `Message` , `uploaded_file`) VALUES ('".$_GET['name']."', '".$_GET['email']."', '".$_GET['Message']."')"); 
echo "Thank you! "; 
} 
?> 
</htm> 
+0

看到http://www.finalwebsites.com/forums/topic/php-e-mail-attachment-script, – GBD

回答

2

您在mail中使用了錯誤的參數來添加附件。查看mail()手冊頁http://php.net/manual/en/function.mail.php

附件並不那麼簡單,而且PHP的vanilla mail命令並不能真正支持它們。如果要在郵件中提交附件,請考慮使用額外的庫,例如Pear::Mailhttp://pear.php.net/package/Mail/redirected

當然,您可以自己實現它,但是您必須深入瞭解Base64編碼和MIME。

+0

非常感謝你 – abhi