I’m trying to create an RMA form and I have everything working except the upload + email attachment.
What I’m trying to do is have the customer upload a scanned copy of their document (in jpeg,gif,png,pdf,word etc formats) but I can’t seem to get things going. I’m up on various file upload methods, but I can’t seem to figure out where to begin.
This is my php code so far
$name=$_POST['first'] ." ".$_POST['last'];
$email=$_POST['email'];
$address=$_POST['street'] ." ". $_POST['city'] ."".$_POST['province'] ." ".$_POST['postal'];
$pod=$_POST['pod'];
$sku=$_POST['sku'];
$description=$_POST['description'];
$problem=$_POST['problem'];
$case_id=$_POST['case_id'];
$status=$_POST['status'];
$phone=$_POST['parea'] ."".$_POST['pfirst'] ."".$_POST['plast'];
$tracking=$_POST['tracking'];
$date=$_POST['date'];
$link = mysql_connect('m', 'sk', 's1');
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db(s);
$status = "Pending";
$tracking = "";
$date = date('c');
$case_id = mt_rand(1252,10000);
while( $fetch = mysql_fetch_array( mysql_query("SELECT `case_id` FROM `webform` WHERE `case_id` = $case_id") ) )
{
$case_id = mt_rand(1252,10000);
}
//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
$error.="Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array ($name,$phone,$email,$address,$pod,$sku,$description,$problem);
$required = array($name,$phone,$email,$address,$pod,$sku,$description,$problem);
$your_email = "fahad@home.com";
$email_subject = "RMA: ".$case_id;
$email_content = "new message:\n";
foreach($values as $key => $value){
if(in_array($value,$required)){
if ($key != $phone && $key != $address)
$email_content .= $value.' '.$_POST[$value]."\n";
}
}
if(@mail($your_email,$email_subject,$email_content,$case_id)) {
echo 'Request Submitted!<br />';
echo 'RMA:'. $case_id;
} else {
echo 'ERROR!';
}
}
$queries = array ($values, $case_id);
$piece = implode(",",$queries);
mysql_query("INSERT INTO `webform` (`case_id`, `name`, `phone`, `email`, `address`, `pod`, `sku`, `description`, `problem`, `status`, `tracking`, `date_recieved`) VALUES ('$case_id', '$name', '$phone', '$email', '$address', '$pod', '$sku','$description', '$problem', '$status', '$tracking', '$date')")
or die(mysql_error());
mysql_close($link);
?>
So basically, I’m not sure where to place the file upload section or even how to use it. I have a working html design for it that brings up the file browser and everything, I just don’t know how to link that process to the php side, and then after uploading attach that to the email.
Thank you kindly in advance for everyone’s help!
I wouldn’t.
My company sends millions of emails monthly and email attachments are the biggest single problem that we have. Bottom line, you attach things and you raise the chances of being blocked or flagged for spam by a significant factor.
Send a link instead. Use a unique hash identifier in the link that the person can click to initiate a download. It makes for a smaller email, more spam friendly delivery, easier coding for you, and happier customers.