Jump to content

File uploads but doesn't attach to the sent email


brandon215

Recommended Posts

Hi! I'm hoping someone can help me out with a HTML form using PHP. The form allows users to upload a file (and that part works) but it's supposed to attach that file in the email it sends with the form info. I've looked and looked and looked but I haven't been able to find a resolution. HELP!!! 

 

<?php
$fileName = $_FILES["fileatt"]["name"]; // The file name
$fileTmpLoc = $_FILES["fileatt"]["tmp_name"]; // File in the PHP tmp folder
$fileType = $_FILES["fileatt"]["type"]; // The type of file it is
$fileSize = $_FILES["fileatt"]["size"]; // File size in bytes
$fileErrorMsg = $_FILES["fileatt"]["error"]; // 0 for false... and 1 for true
 
move_uploaded_file($fileTmpLoc, "uploads/$fileName");
 
if (is_uploaded_file($fileatt)) {
  // Read the file to be attached ('rb' = read binary)
  $file = fopen($fileatt,'rb');
  $data = fread($file,filesize($fileatt));
  fclose($file);
}
$data = chunk_split(base64_encode($data));
 
 
 
$From = $_POST['From'];
$Email = $_POST['Email'];
$Campaign = $_POST['Campaign'];
$Subject = $_POST['Subject'];
$email_sub = "Email request confirmation";
$datepicker = $_POST['datepicker'];
$Specialty = implode(', ', empty($_POST['Specialty']) ? array() : $_POST['Specialty'] );
$Template = $_POST['Template'];
$Notes = $_POST['Notes'];
$formcontent=" New Email Request from $Name \n \n --------------------------------------- \n \n From: $From \n Email: $Email \n Campaign: $Campaign \n Subject: $Subject \n Date: $datepicker \n Specialty: $Specialty \n Template: $Template \n Uploaded File: $fileName \n Notes: $Notes $data";
$formcontent2=" Hey there! Thanks for submitting your request, here's a copy of the information you submitted. \n \n --------------------------------------- \n \n From: $From \n Email: $Email \n Campaign: $Campaign \n Subject: $Subject \n Date: $datepicker \n Specialty: $Specialty \n Uploaded File: $fileName \n Template: $Template \n Notes: $Notes";
 
$recipient = "[email protected]";
$subject = "2013 Email Request";
mail($recipient, $subject, $formcontent,'From: [email protected]','-f [email protected]' ) or die("Error!");
mail($Email, $email_sub, $formcontent2,'From: [email protected]','-f [email protected]' ) or die("Error!");
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';  
?>
 

 

index.html

mail.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.