发送带附件的邮件。发送邮件成功但文件未上传

时间:2013-07-25 06:13:09

标签: php sendmail email-attachments

我的代码工作正常。邮件也很好。但该文件未上传。我以为我的孔码很好。但我无法理解为什么我的代码不起作用。

我的PHP代码

include("config.php");
$NOW_DATE = date("Y-m-d");
$NOW_TIME = date("Y-m-d H:i:s");
$STARTtime = date("U");
// Here we get all the information from the fields sent over by the form.
$cname = $_POST['cname'];
$cmobilenumber = $_POST['cmobilenumber'];
$cemailaddress = $_POST['cemailaddress'];
$ccountry = $_POST['ccountry'];
$cmessage = $_POST['cmessage'];
$allowedExts = array("pdf", "xlsx", "doc", "docx", "ppt");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "application/msword")
|| ($_FILES["file"]["type"] == "application/ application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|| ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.presentationml.presentation")
|| ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
|| ($_FILES["file"]["type"] == "application/pdf"))
&& ($_FILES["file"]["size"] < 200000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 3072) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("upload/" . $_FILES["file"]["name"]))
  {
  echo $_FILES["file"]["name"] . " already exists. ";
  }
else
  {
  move_uploaded_file($_FILES["file"]["tmp_name"],
  "upload/" . $_FILES["file"]["name"]);
  echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
  }
  }
}
else
 { 
 echo "Invalid file";
 }
$sql = "insert into resume values('','$cname','$cmobilenumber','$cemailaddress','$NOW_TIME','$ccountry','$cmessage')";
$rsd = mysql_query($sql);
$to = 'marvanjaam@gmail.com';
$subject = "Resume";
$message = 'From: '.$cname.' Email: '.$cemailaddress.'Message: '.$cmessage;
$headers = 'From: '.$cemailaddress. "\r\n";
if (filter_var($cemailaddress, FILTER_VALIDATE_EMAIL)) { // this line checks that we have a valid email address
mail($to, $subject, $message, $headers); //This method sends the mail.
echo "Your email was successfully sent!";
     // success message
}else{
echo " your mail was failed";
};

发送邮件工作正常。但文件没有上传。

0 个答案:

没有答案