如何发送带附件的文本邮件?

时间:2011-04-13 07:39:08

标签: php email attachment

  

可能重复:
  php send e-mail with attachment

我发送附件邮件。附件将发送但文本邮件未发送。 这是我的代码:

$tmp = $_FILES['uploadimage']['tmp_name'];
$sep = md5(time());
$filename = $_FILES['uploadimage']['name'];

$filedata = file_get_contents($tmp); //Get file contents
$fdata = chunk_split(base64_encode($filedata)); //Encode data into text form


$message = "
<table border=0 cellpadding=3 cellspacing=3 align=center width=95% style=border:1px solid #000000;>
 <tr >
<td  valign=top >
<table border=0 cellpadding=3 cellspacing=3 align=center width=100%>
<tr >
<td  style=padding-left:5px; ><font color=#000000 size=2 face=Arial ><b>Dear,".$Name."</font></td>
</tr>
<tr>
<td style=padding-left:5px;><strong>Your message details as below:</strong></td>
</tr>
</table>";
$message.=" 
<table border=0 cellpadding=0 cellspacing=0  width=93%>
<tr  bgcolor=#1D1D1D style=color:#FFFFFF;>
  <td  align=center colspan=2> <font size=2 face=Arial color=#FFFFFF><strong >Message Details</strong></font></td>
</tr>
<tr>
  <td  align=center colspan=2> <font size=2 face=Arial color=#5F5D5E><strong> ";
  if($Name !=''){
$message.="
  <table width=620 border=0 align=center   cellpadding=0 cellspacing=0  >
<tr>
<td>
<table width=93% border=0 bgcolor=#FFFFFF  color:#000000 >
<tr>
    <td><font size=2 face=Arial color=#5F5D5E><strong>Name :</strong></font></td>
    <td>".$Name." ";}
     if($Phone_No !='')
     {
$message.=" 
    </td>
</tr>
<tr>
    <td><font size=2 face=Arial color=#5F5D5E><strong>Phone No :</strong></font></td>
    <td>".$Phone_No." "; }
$message.=" 
    </td>
</tr>

<tr>
    <td><font size=2 face=Arial color=#5F5D5E><strong>Sex :</strong></font></td>
    <td>".$Sex." ";
$message.=" 
    </td>
</tr>
<tr>
    <td><font size=2 face=Arial color=#5F5D5E><strong>Age :</strong></font></td>
    <td>".$Age."</td>
</tr>";
$message.="<tr>
    <td>Height :</td>
    <td>".$Height."</td>
</tr>";
$message.="
<tr>
    <td><font size=2 face=Arial color=#5F5D5E><strong>Weight :</strong></font></td>
    <td>".$Weight."</td>
</tr>";

$message.="
<tr>
    <td><font size=2 face=Arial color=#5F5D5E><strong>Hair Color :</strong></font></td>
    <td>".$Hair_Color."</td>
</tr>";
$message.="
<tr>
    <td><font size=2 face=Arial color=#5F5D5E><strong>Eye Color :</strong></font></td>
    <td>".$Eye_Color."</td>
</tr>";
$message.="
<tr>
    <td><font size=2 face=Arial color=#5F5D5E><strong>Complexion :</strong></font></td>
    <td>".$Complexion."</td>
</tr>";
$message.="


<tr>
    <td><font size=2 face=Arial color=#5F5D5E><strong>Build :</strong></font></td>
    <td>".$Build."</td>
</tr>";
$message.="
<tr>
    <td><font size=2 face=Arial color=#5F5D5E><strong>addinfo :</strong></font></td>
    <td>".$addinfo."</td>
</tr>
<tr>
    <td><font size=2 face=Arial color=#5F5D5E><strong>Make :</strong></font></td>
    <td>".$Make."</td>
</tr>
<tr>
    <td><font size=2 face=Arial color=#5F5D5E><strong>Model If Known :</strong></font></td>
    <td>".$Model_If_Known."</td>
</tr>
<tr>
    <td><font size=2 face=Arial color=#5F5D5E><strong>Body Type :</strong></font></td>
    <td>".$Body_Type."</td>
</tr>
<tr>
    <td><font size=2 face=Arial color=#5F5D5E><strong>Color :</strong></font></td>
    <td>".$Color."</td>
</tr>
<tr>
    <td><font size=2 face=Arial color=#5F5D5E><strong>State of Tag :</strong></font></td>
    <td>".$State_of_Tag."</td>
</tr>
<tr>
    <td><font size=2 face=Arial color=#5F5D5E><strong>Where did you see this...?</strong></font></td>
    <td>".$where_did."</td>
</tr>
<tr>
    <td><font size=2 face=Arial color=#5F5D5E><strong>When did you see this...?</strong></font></td>
    <td>".$when_did."</td>
</tr>
<tr>
    <td><font size=2 face=Arial color=#5F5D5E><strong>Why is this a suspicious  incident?.. What did you see?</strong></font></td>
    <td>".$suspicious."</td>
</tr>


</table>
</td>
</tr>
</table> 

";   

$message.="

</strong></font>
  </td>
</tr>
</table>
";
$message.="
<table border=0 cellpadding=3 cellspacing=3  width=100%>
<tr >
  <td  align=left colspan=2><font color=#000000 size=2 face=Arial> <strong >Regards </strong></font></td>

</tr>
<tr >
  <td  align=left colspan=2><font color=#000000 size=2 face=Arial> Appsbee</font></td>

</tr>
</table>
</td>
</tr>
</table>";



$subject ="Information";
//Determine mime type
$ext = explode('.', $filename);
$ext = $ext[1];

if($ext == "JPG" || $ext == "jpg" || $ext == "JPEG" || $ext == "jpeg") {
$mime_type = "image/jpeg";
}
elseif($ext == "gif" || $ext == "GIF") {
$mime_type = "image/gif";
}
elseif($ext == "bmp" || $ext == "BMP") {
$mime_type = "image/bmp"; 
}
elseif($ext == "txt" || $ext == "TXT") {
$mime_type = "text/plain";
}
else {
echo("Error: Wrong file type!");
}

$header = "From: \"From Name\" <{$Name}>
MIME-Version: 1.0
Content-Type: Multipart/Mixed;
  boundary=\"$sep\"

charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit

--$sep
Content-Type: $mime_type;
  name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
        filename=\"$filename\"

$fdata
--$sep";




@mail($email, $subject, $message, $header);

1 个答案:

答案 0 :(得分:1)

尝试PHPMailer

非常简单,将为您处理上述所有事情..