i simply make a form to submit job application. Everything working just fine but i want a little bit improvement where uploaded files also forwarded to my email. i want to make it easier for me to see the attachment files without copy-paste link from my email. Also i wonder if somehow i can make the subject email is 'name' ?
<?php
$mail = $_POST['email'];
$to = "yadayadayada";
$subject = "--";
$headers = "Job application <noreply@example.com>";
$message = "Personal Info\n";
$message .= "\nFirst and Last Name: " . $_POST['name'];
$message .= "\nEmail: " . $_POST['email'];
$message .= "\nDOB: " . $_POST['dob'];
$message .= "\nTelephone: " . $_POST['phone'];
$message .= "\nGender: " . $_POST['gender'];
/* FILE UPLOAD */
if(isset($_FILES['fileupload'])){
$errors= array();
$file_name = $_FILES['fileupload']['name'];
$file_size =$_FILES['fileupload']['size'];
$file_tmp =$_FILES['fileupload']['tmp_name'];
$file_type=$_FILES['fileupload']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['fileupload']['name'])));
$expensions= array("pdf","doc","docx", "jpeg", "gif", "png");
$OriginalFilename = $FinalFilename = preg_replace('`[^a-z0-9-_.]`i','',$_FILES['fileupload']['name']);
$FileCounter = 1;
while (file_exists( 'upload_files/'.$FinalFilename ))
$FinalFilename = $FileCounter++.'_'.$OriginalFilename;
if(in_array($file_ext,$expensions)=== false){
$errors[]="Extension not allowed, please choose a .pdf, .doc, .docx, .jpeg, .png, .gif file.";
}
if($file_size > 15360){
$errors[]='File size must be max 15000Kb';
}
if(empty($errors)==true){
$message .= "\nResume: example.com/upload_files/".$FinalFilename;
}else{
$message .= "\nFile name: no files uploaded";
}
};
/* end FILE UPLOAD */
$message .= "\n\nWORK AVAILABILITY";
$message .= "\nAre you available for work: " . $_POST['availability'];
if (isset($_POST['minimum_salary_full_time']) && $_POST['minimum_salary_full_time'] != "")
{
$message .= "\nMinimum salary: " . $_POST['minimum_salary_full_time'];
$message .= "\nHow soon would you be looking to start? " . $_POST['start_availability_full_time'];
$message .= "\nAre you willing to work remotely? " . $_POST['remotely_full_time'];
}
if (isset($_POST['minimum_salary_part_time']) && $_POST['minimum_salary_part_time'] != "")
{
$message .= "\nMinimum salary: " . $_POST['minimum_salary_part_time'];
$message .= "\nHow soon would you be looking to start? " . $_POST['start_availability_part_time'];
$message .= "\nWhen you prefer to work? " . $_POST['day_preference_part_time'];
}
if (isset($_POST['fixed_rate_contract']) && $_POST['fixed_rate_contract'] != "")
{
$message .= "\nMinimum fixed rate: " . $_POST['fixed_rate_contract'];
$message .= "\nMinimum hourly rate: " . $_POST['hourly_rate_contract'];
$message .= "\nMinimum hours for a contract: " . $_POST['minimum_hours_conctract'];
$message .= "\nAre you willing to work remotely? " . $_POST['remotely_contract'];
}
$message .= "\n\nTerms and conditions accepted: " . $_POST['terms'];
//Receive Variable
$sentOk = mail($to,$subject,$message,$headers);
//Confirmation page
$user = "$mail";
$usersubject = "Thank You";
$userheaders = "From: Job application <noreply@mydomain.com>";
/*$usermessage = "Thank you for your time. Your application is successfully submitted.\n"; WITHOUT SUMMARY*/
//Confirmation page WITH SUMMARY
$usermessage = "Thank you for your time. Your application is successfully submitted. We will contact you shortly.\n\nBELOW A SUMMARY\n\n$message";
mail($user,$usersubject,$usermessage,$userheaders);
?>
I try to add this it doesnt work
}
if(empty($errors)==true){
move_uploaded_file($file_tmp,"upload_files/".$FinalFilename);
$mail->addAttachment ("upload_files/".$FinalFilename);
}else{
$message .= "\nFile name: no files uploaded";
}
};