chrismarsden Posted May 8, 2010 Share Posted May 8, 2010 Hi guys, I was wondering if you could help me: I have just finished creating fire by scratching my head while creating a contact form which sends email to me with the users inputted info, its only basic but im now going to be using the base of that to start a job application form which should not be to hard... my problem is that I want the user to be able to attach their CV to the form... is this possible with what is effectively a contact form??? thanks guys. Quote Link to comment Share on other sites More sharing options...
chrismarsden Posted May 8, 2010 Author Share Posted May 8, 2010 Figured the code im using might help: applyforajob.php: <!-- Content unit - One column --> <div class="column1-unit"> <h1>Apply For A Position</h1> <br> <h3>Please Complete The Online Application Below, Fields Marked with * Are Mandatory:<p></h3> <!-- Content unit - One column --> <div class="column1-unit"> <div class="contactform"> <form method="POST" action="applysettings.php"> <fieldset><legend> Candidate Details </legend> <p><label for="contact_title">Title:* </label><br> <select name="contact_title" class="combo"> <option value="choose"> Select... </option> <option value="mr"> Mr. </option> <option value="mrs"> Mrs. </option> <option value="mr"> Ms. </option> <option value="mr"> Miss. </option> <option value="dr"> Dr. </option></select> <p>First Name:* <br> <input type="text" name="Firstname" class="field" value="" tabindex="1"> <p>Surname:* <br> <input type="text" name="Surname" class="field" value="" tabindex="2"> <p>Date Of Birth:* <br> <input type="text" name="DOB" class="field" value="DD/MM/YYYY" tabindex="3"> <p>First Line Of Address:* <br> <input type="text" name="Address1" class="field" value="" tabindex="4"> <p>City:* <br> <input type="text" name="Address2" class="field" value="" tabindex="5"> <p>Postcode:* <br> <input type="text" name="Postcode" class="field" value="" tabindex="6"> <p>Email Address:* <br> <input type="text" name="EmailFrom" class="field" value="" tabindex="7"> <p>Contact Number:* <br> <input type="text" name="Telephone" class="field" value="" tabindex="8"> </fieldset> <fieldset><legend> Eligibility - Please Delete As Applicable </legend> <p>Can you provide a passport showing you are a British Citizen, or have a right of abode in the United Kingdom; OR:<br> <input type="text" name="elig1" class="field" value="Yes / No / Not Applicable" tabindex="9"> <p>Can you provide a document showing that you are a national of a European Economic Area country or Switzerland. This must be a national passport or national identity card; OR:<br> <input type="text" name="elig2" class="field" value="Yes / No / Not Applicable" tabindex="10"> <p>Can you provide a residence permit issued by the Home Office to a national from a European Economic Area country or Switzerland; OR:<br> <input type="text" name="elig3" class="field" value="Yes / No / Not Applicable" tabindex="11"> <p>Can you provide a passport or other document issued by the Home Office which has an endorsement stating that you have a current right of residence in the United Kingdom as the family member of a national from a European Economic Area country or Switzerland who is resident in the United Kingdom; OR:<br> <input type="text" name="elig4" class="field" value="Yes / No / Not Applicable" tabindex="12"> <p>Can you provide a passport or other travel document endorsed to show that you can stay indefinitely in the United Kingdom, or has no time limit on your stay; OR:<br> <input type="text" name="elig5" class="field" value="Yes / No / Not Applicable" tabindex="13"> <p>Can you provide a a passport or other travel document endorsed to show that you can stay in the United Kingdom; and that this endorsement allows you to do the type of work we are offering if you do not have a work permit; OR:<br> <input type="text" name="elig6" class="field" value="Yes / No / Not Applicable" tabindex="14"> <p>Can you provide an Application Registration Card issued by the Home Office stating you are permitted to take employment:<br> <input type="text" name="elig7" class="field" value="Yes / No / Not Applicable" tabindex="15"> <p> If None Of The Above Can Be Provided Please Do Not Continue With This Application. </fieldset> <fieldset><legend> Position Applying For & Why You Think Your Suitable: </legend> <P><label for="Position">Please State Which Position Your Are Applying For:* </label><br> <select name="Position" class="combo" tabindex="16"> <option value="choose"> Select... </option> <option value="Accounts_Manager"> SME Business Accounts Manager. </option> <option value="Senior_Accounts_Manager"> Senior SME Business Accounts Manager. </option> <option value="Administrator"> Administrator. </option> <option value="Human_Resources_Officer"> Human Resources Officer. </option> <p> </select> <p>Why You Think You Are Suitable For The Role:<br> <textarea name="Whyyou" id="Whyyou" cols="55" rows="10" tabindex="17"></textarea></p> </fieldset> <p><input type="submit" name="submit" value="Submit" class="button" tabindex="18"> </form> </div> </div> applysettings.php: <?php // get posted data into local variables $EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); $EmailTo = "chris_mars@hotmail.co.uk"; $Subject = "Website Application"; $contact_title = Trim(stripslashes($_POST['contact_title'])); $Firstname = Trim(stripslashes($_POST['Firstname'])); $Surname = Trim(stripslashes($_POST['Surname'])); $DOB = Trim(stripslashes($_POST['DOB'])); $Address1 = Trim(stripslashes($_POST['Address1'])); $Address2 = Trim(stripslashes($_POST['Address2'])); $Postcode = Trim(stripslashes($_POST['Postcode'])); $Telephone = Trim(stripslashes($_POST['Telephone'])); $elig1 = Trim(stripslashes($_POST['elig1'])); $elig2 = Trim(stripslashes($_POST['elig2'])); $elig3 = Trim(stripslashes($_POST['elig3'])); $elig4 = Trim(stripslashes($_POST['elig4'])); $elig5 = Trim(stripslashes($_POST['elig5'])); $elig6 = Trim(stripslashes($_POST['elig6'])); $elig7 = Trim(stripslashes($_POST['elig7'])); $Position = Trim(stripslashes($_POST['Position'])); $Whyyou = Trim(stripslashes($_POST['Whyyou'])); // validation $validationOK=true; if (Trim($contact_title)=="choose") $validationOK=false; if (Trim($EmailFrom)=="") $validationOK=false; if (Trim($Firstname)=="") $validationOK=false; if (Trim($Surname)=="") $validationOK=false; if (Trim($DOB)=="") $validationOK=false; if (Trim($Address1)=="") $validationOK=false; if (Trim($Address2)=="") $validationOK=false; if (Trim($Postcode)=="") $validationOK=false; if (Trim($Telephone)=="") $validationOK=false; if (Trim($Position)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=errorapp.php\">"; exit; } // prepare email body text $Body = ""; $Body .= "Title: "; $Body .= $contact_title; $Body .= "\n"; $Body .= "\n"; $Body .= "First Name: "; $Body .= $Firstname; $Body .= "\n"; $Body .= "\n"; $Body .= "Surname: "; $Body .= $Surname; $Body .= "\n"; $Body .= "\n"; $Body .= "DOB: "; $Body .= $DOB; $Body .= "\n"; $Body .= "\n"; $Body .= "First Line Of Address: "; $Body .= $Address1; $Body .= "\n"; $Body .= "\n"; $Body .= "Second Line Of Address: "; $Body .= $Address2; $Body .= "\n"; $Body .= "\n"; $Body .= "Post Code: "; $Body .= $Postcode; $Body .= "\n"; $Body .= "\n"; $Body .= "Contact Number: "; $Body .= $Telephone; $Body .= "\n"; $Body .= "\n"; $Body .= "Eligibility Answer 1: "; $Body .= $elig1; $Body .= "\n"; $Body .= "\n"; $Body .= "Eligibility Answer 2: "; $Body .= $elig2; $Body .= "\n"; $Body .= "\n"; $Body .= "Eligibility Answer 3: "; $Body .= $elig3; $Body .= "\n"; $Body .= "\n"; $Body .= "Eligibility Answer 4: "; $Body .= $elig4; $Body .= "\n"; $Body .= "\n"; $Body .= "Eligibility Answer 5: "; $Body .= $elig5; $Body .= "\n"; $Body .= "\n"; $Body .= "Eligibility Answer 6: "; $Body .= $elig6; $Body .= "\n"; $Body .= "\n"; $Body .= "Eligibility Answer 7: "; $Body .= $elig7; $Body .= "\n"; $Body .= "\n"; $Body .= "Position Applying For: "; $Body .= $Position; $Body .= "\n"; $Body .= "\n"; $Body .= "Why The Candidate Is Applying: "; $Body .= $Whyyou; $Body .= "\n"; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=okapp.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=errorapp.php\">"; } ?> Quote Link to comment Share on other sites More sharing options...
chrismarsden Posted May 8, 2010 Author Share Posted May 8, 2010 the above code has been updated but im still really stuck if any one has any solutions??? Quote Link to comment Share on other sites More sharing options...
chrismarsden Posted May 8, 2010 Author Share Posted May 8, 2010 ok I have been playing around with this which i took out of a pre written script which i was directed to on an old forum post... realy can not get it to work... PLEASE HELP ME BEFORE I BURN MY COMPUTER! applyforajob.php <div class="column1-unit"> <div class="contactform"> <form method="POST" action="applysettings.php" enctype="multipart/form-data"> <fieldset><legend> Candidate Details </legend> <p><label for="contact_title">Title:* </label><br> <select name="contact_title" class="combo"> <option value="Choose"> Select... </option> <option value="Mr"> Mr. </option> <option value="Mrs"> Mrs. </option> <option value="Ms"> Ms. </option> <option value="Miss"> Miss. </option> <option value="Dr"> Dr. </option></select> <p>First Name:* <br> <input type="text" name="Firstname" class="field" value="" tabindex="1"> <p>Surname:* <br> <input type="text" name="Surname" class="field" value="" tabindex="2"> <p>Date Of Birth:* <br> <input type="text" name="DOB" class="field" value="DD/MM/YYYY" tabindex="3"> <p>First Line Of Address:* <br> <input type="text" name="Address1" class="field" value="" tabindex="4"> <p>City:* <br> <input type="text" name="Address2" class="field" value="" tabindex="5"> <p>Postcode:* <br> <input type="text" name="Postcode" class="field" value="" tabindex="6"> <p>Email Address:* <br> <input type="text" name="EmailFrom" class="field" value="" tabindex="7"> <p>Contact Number:* <br> <input type="text" name="Telephone" class="field" value="" tabindex="8"> </fieldset> <fieldset><legend> Eligibility - Please Delete As Applicable </legend> <p>Can you provide a passport showing you are a British Citizen, or have a right of abode in the United Kingdom:<br> <input type="radio" name="elig1" value="Yes" tabindex="9">Yes <br> <input type="radio" name="elig1" value="No" tabindex="9">No <p> <h3>NOTE: If the above question has been answered Yes - Please skip to qualifactions & education</h3><p> <p>Can you provide a document showing that you are a national of a European Economic Area country or Switzerland. This must be a national passport or national identity card:<br> <input type="radio" name="elig2" value="Yes" tabindex="10">Yes <br> <input type="radio" name="elig2" value="No" tabindex="10">No <p>Can you provide a residence permit issued by the Home Office to a national from a European Economic Area country or Switzerland:<br> <input type="radio" name="elig3" value="Yes" tabindex="11">Yes <br> <input type="radio" name="elig3" value="No" tabindex="11">No <p>Can you provide a passport or other document issued by the Home Office which has an endorsement stating that you have a current right of residence in the United Kingdom as the family member of a national from a European Economic Area country or Switzerland who is resident in the United Kingdom:<br> <input type="radio" name="elig4" value="Yes" tabindex="12">Yes <br> <input type="radio" name="elig4" value="No" tabindex="12">No <p>Can you provide a passport or other travel document endorsed to show that you can stay indefinitely in the United Kingdom, or has no time limit on your stay:<br> <input type="radio" name="elig5" value="Yes" tabindex="13">Yes <br> <input type="radio" name="elig5" value="No" tabindex="13">Yes <p>Can you provide a a passport or other travel document endorsed to show that you can stay in the United Kingdom; and that this endorsement allows you to do the type of work we are offering if you do not have a work permit:<br> <input type="radio" name="elig6" value="Yes" tabindex="14">Yes<br> <input type="radio" name="elig6" value="No" tabindex="14">No <p>Can you provide an Application Registration Card issued by the Home Office stating you are permitted to take employment:<br> <input type="radio" name="elig7" value="Yes" tabindex="15">Yes <br> <input type="radio" name="elig7" value="No" tabindex="15">No <p> If None Of The Above Can Be Provided Please Do Not Continue With This Application. </fieldset> <fieldset><legend> Qualifactions & Education: </legend> <p>Please provide details of your education so far:<br> <textarea name="Education" id="Education" cols="55" rows="10" tabindex="16"></textarea></p> </fieldset> <fieldset><legend> Employment History: </legend> <p>Please provide details of your previous employment:<br> <p>Name Of Employer:<br> <input type="text" name="Employer_Name" class="field" value="" tabindex="17"> <p> <p>Employer Address:<br> <input type="text" name="Employer_Address" class="field" value="" tabindex="18"> <p> <p>Superviser Or Manager Name:<br> <input type="text" name="Manager_Name" class="field" value="" tabindex="19"> <p> <p>Employers Contact Number:<br> <input type="text" name="Employer_Contact" class="field" value="" tabindex="20"> <p> <p>Employers Email Address:<br> <input type="text" name="Employer_Email" class="field" value="" tabindex="21"> <p> <p>Position Title:<br> <input type="text" name="Position_Title" class="field" value="" tabindex="22"> <p> <p>Salary:<br> <input type="text" name="Salary" class="field" value="" tabindex="23"> <p> <p>Reason For Leaving:<br> <input type="text" name="Leaving_Reason" class="field" value="" tabindex="24"> <p> <p>Responsibilities:<br> <textarea name="Responsibilities" id="Responsibilities" cols="55" rows="10" tabindex="25"></textarea></p> <p>May We Contact Your Employer:<br> <input type="radio" name="Can_We_Contact" value="Yes" tabindex="26">Yes <BR> <input type="radio" name="Can_We_Contact" value="No" tabindex="26">No <p> </fieldset> <fieldset><legend> Employer References: </legend> <p>Name / Relationship / Address / Phone:<br> <textarea name="Referances" id="Referances" cols="55" rows="10" tabindex="27"></textarea></p> </fieldset> <fieldset><legend> Position Applying For & Why You Think Your Suitable: </legend> <P><label for="Position">Please State Which Position You Are Applying For:* </label><br> <select name="Position" class="combo" tabindex="28"> <option value="choose"> Select... </option> <option value="Accounts_Manager"> SME Business Accounts Manager. </option> <option value="Senior_Accounts_Manager"> Senior SME Business Accounts Manager. </option> <option value="Administrator"> Administrator. </option> <option value="Human_Resources_Officer"> Human Resources Officer. </option> <p> </select> <p>Please Upload Your CV:<br> <p><input type="file" name="attachment"></p> <p>Why You Think You Are Suitable For The Role:<br> <textarea name="Whyyou" id="Whyyou" cols="55" rows="10" tabindex="29"></textarea></p> </fieldset> <p><input type="submit" name="submit" value="Submit" class="button" tabindex="30"> </form> </div> </div> applysettings.php <?php // get posted data into local variables $EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); $EmailTo = "chris_mars@hotmail.co.uk"; $Subject = "Website Application"; $contact_title = Trim(stripslashes($_POST['contact_title'])); $Firstname = Trim(stripslashes($_POST['Firstname'])); $Surname = Trim(stripslashes($_POST['Surname'])); $DOB = Trim(stripslashes($_POST['DOB'])); $Address1 = Trim(stripslashes($_POST['Address1'])); $Address2 = Trim(stripslashes($_POST['Address2'])); $Postcode = Trim(stripslashes($_POST['Postcode'])); $Telephone = Trim(stripslashes($_POST['Telephone'])); $elig1 = Trim(stripslashes($_POST['elig1'])); $elig2 = Trim(stripslashes($_POST['elig2'])); $elig3 = Trim(stripslashes($_POST['elig3'])); $elig4 = Trim(stripslashes($_POST['elig4'])); $elig5 = Trim(stripslashes($_POST['elig5'])); $elig6 = Trim(stripslashes($_POST['elig6'])); $elig7 = Trim(stripslashes($_POST['elig7'])); $Education = Trim(stripslashes($_POST['Education'])); $Employer_Name = Trim(stripslashes($_POST['Employer_Name'])); $Employer_Address = Trim(stripslashes($_POST['Employer_Address'])); $Manager_Name = Trim(stripslashes($_POST['Manager_Name'])); $Employer_Contact = Trim(stripslashes($_POST['Employer_Contact'])); $Employer_Email = Trim(stripslashes($_POST['Employer_Email'])); $Position_Title = Trim(stripslashes($_POST['Position_Title'])); $Salary = Trim(stripslashes($_POST['Salary'])); $Leaving_Reason = Trim(stripslashes($_POST['Leaving_Reason'])); $Responsibilities = Trim(stripslashes($_POST['Responsibilities'])); $Can_We_Contact = Trim(stripslashes($_POST['Can_We_Contact'])); $Referances = Trim(stripslashes($_POST['Referances'])); $attachment = Trim(stripslashes($_POST['attachment'])); $Position = Trim(stripslashes($_POST['Position'])); $Whyyou = Trim(stripslashes($_POST['Whyyou'])); $attachment_fields[1] = Trim(stripslashes($_POST['attachments'])); $attachment_fields[1]=""; // validation $validationOK=true; if (Trim($contact_title)=="choose") $validationOK=false; if (Trim($EmailFrom)=="") $validationOK=false; if (Trim($Firstname)=="") $validationOK=false; if (Trim($Surname)=="") $validationOK=false; if (Trim($DOB)=="") $validationOK=false; if (Trim($Address1)=="") $validationOK=false; if (Trim($Address2)=="") $validationOK=false; if (Trim($Postcode)=="") $validationOK=false; if (Trim($Telephone)=="") $validationOK=false; if (Trim($Position)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=errorapp.php\">"; exit; } // prepare email body text $Body = ""; $Body .= "Title: "; $Body .= $contact_title; $Body .= "\n"; $Body .= "\n"; $Body .= "First Name: "; $Body .= $Firstname; $Body .= "\n"; $Body .= "\n"; $Body .= "Surname: "; $Body .= $Surname; $Body .= "\n"; $Body .= "\n"; $Body .= "DOB: "; $Body .= $DOB; $Body .= "\n"; $Body .= "\n"; $Body .= "First Line Of Address: "; $Body .= $Address1; $Body .= "\n"; $Body .= "\n"; $Body .= "Second Line Of Address: "; $Body .= $Address2; $Body .= "\n"; $Body .= "\n"; $Body .= "Post Code: "; $Body .= $Postcode; $Body .= "\n"; $Body .= "\n"; $Body .= "Contact Number: "; $Body .= $Telephone; $Body .= "\n"; $Body .= "\n"; $Body .= "Eligibility Answer 1: "; $Body .= $elig1; $Body .= "\n"; $Body .= "\n"; $Body .= "Eligibility Answer 2: "; $Body .= $elig2; $Body .= "\n"; $Body .= "\n"; $Body .= "Eligibility Answer 3: "; $Body .= $elig3; $Body .= "\n"; $Body .= "\n"; $Body .= "Eligibility Answer 4: "; $Body .= $elig4; $Body .= "\n"; $Body .= "\n"; $Body .= "Eligibility Answer 5: "; $Body .= $elig5; $Body .= "\n"; $Body .= "\n"; $Body .= "Eligibility Answer 6: "; $Body .= $elig6; $Body .= "\n"; $Body .= "\n"; $Body .= "Eligibility Answer 7: "; $Body .= $elig7; $Body .= "\n"; $Body .= "\n"; $Body .= "Education: "; $Body .= $Education; $Body .= "\n"; $Body .= "\n"; $Body .= "Previous Employer Name: "; $Body .= $Employer_Name; $Body .= "\n"; $Body .= "\n"; $Body .= "Employers Address: "; $Body .= $Employer_Address; $Body .= "\n"; $Body .= "\n"; $Body .= "Manager Name: "; $Body .= $Manager_Name; $Body .= "\n"; $Body .= "\n"; $Body .= "Employer Phone Number: "; $Body .= $Employer_Contact; $Body .= "\n"; $Body .= "\n"; $Body .= "Employer Email: "; $Body .= $Employer_Email; $Body .= "\n"; $Body .= "\n"; $Body .= "Position Held: "; $Body .= $Position_Title; $Body .= "\n"; $Body .= "\n"; $Body .= "Salary: "; $Body .= $Salary; $Body .= "\n"; $Body .= "\n"; $Body .= "Reason For Leaving: "; $Body .= $Leaving_Reason; $Body .= "\n"; $Body .= "\n"; $Body .= "Responsibilities Held: "; $Body .= $Responsibilities; $Body .= "\n"; $Body .= "\n"; $Body .= "Can We Contact Previous Employer: "; $Body .= $Can_We_Contact; $Body .= "\n"; $Body .= "\n"; $Body .= "Referances: "; $Body .= $Referances; $Body .= "\n"; $Body .= "\n"; $Body .= "Position Applying For: "; $Body .= $Position; $Body .= "\n"; $Body .= "\n"; $Body .= "Why The Candidate Is Applying: "; $Body .= $Whyyou; $Body .= "\n"; $Body .= "\n"; $Body .= "Attachment: "; $Body .= $attachment_fields[1]; $Body .= "\n"; $Body .= "\n"; function getAttachments($attachment_fields, $message, $content_type, $border) { $att_message="This is a multi-part message in MIME format.\r\n"; $att_message.="--{$border}\r\n"; $att_message.=$content_type."\r\n"; $att_message.="Content-Transfer-Encoding: 7bit\r\n\r\n"; $att_message.=$message."\r\n\r\n"; $att_check=preg_split('/,/',$attachment_fields); $att_run=sizeof($att_check); for($i=0;$i<$att_run;$i++) { $fileatt=$_FILES[$att_check[$i]]['tmp_name']; $fileatt_name=$_FILES[$att_check[$i]]['name']; $fileatt_type=$_FILES[$att_check[$i]]['type']; if (is_uploaded_file($fileatt)) { $file=fopen($fileatt,'rb'); $data=fread($file,filesize($fileatt)); fclose($file); $data=chunk_split(base64_encode($data)); $att_message.="--{$border}\n"; $att_message.="Content-Type: {$fileatt_type}; name=\"{$fileatt_name}\"\r\n"; $att_message.="Content-Disposition: attachment; filename=\"{$fileatt_name}\"\r\n"; $att_message.="Content-Transfer-Encoding: base64\r\n\r\n".$data."\r\n\r\n"; } } $att_message.="--{$border}--\n"; return $att_message; } // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=okapp.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=errorapp.php\">"; } ?> Quote Link to comment Share on other sites More sharing options...
litebearer Posted May 8, 2010 Share Posted May 8, 2010 lots of code to read thru. Let's start with what error/result are you getting? Quote Link to comment Share on other sites More sharing options...
chrismarsden Posted May 8, 2010 Author Share Posted May 8, 2010 Im not getting one which is more annoying, it gives me the normal, your application has been received page, it just doesn't send the attachment, it does however send the rest of the email. Quote Link to comment Share on other sites More sharing options...
litebearer Posted May 9, 2010 Share Posted May 9, 2010 Perhaps this may be a contributing factor... $attachment_fields[1] = Trim(stripslashes($_POST['attachments'])); $attachment_fields[1]=""; you have set the value to nothing Quote Link to comment Share on other sites More sharing options...
chrismarsden Posted May 9, 2010 Author Share Posted May 9, 2010 what should i have set it to and will it work if i set it to whatever? Quote Link to comment Share on other sites More sharing options...
litebearer Posted May 9, 2010 Share Posted May 9, 2010 I suppose the question is what value do you hope/expect to be there? You 'grab' it from the form, but then you turn right around and empty it without using the value from the form. Quote Link to comment Share on other sites More sharing options...
chrismarsden Posted May 9, 2010 Author Share Posted May 9, 2010 i hope it will be set to sending me the attachment how ever this may be done you can call it what ever you want so long as it works lmao ... sorry im being thick but im new to php if you have not figured... Quote Link to comment Share on other sites More sharing options...
litebearer Posted May 9, 2010 Share Posted May 9, 2010 No problem! I would presume you are hoping it is the name/location of a file of some sort? Quote Link to comment Share on other sites More sharing options...
chrismarsden Posted May 9, 2010 Author Share Posted May 9, 2010 yeah i think so... so long as the file comes through on the email im not bothered. Quote Link to comment Share on other sites More sharing options...
litebearer Posted May 9, 2010 Share Posted May 9, 2010 I took some liberties and 'touched-up' your code a bit. Included some comments. Look thru it and see what you think as well as see if you have answers. <?php ####################################### # get posted data into local variables ####################################### $EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); $EmailTo = "chris_mars@hotmail.co.uk"; $Subject = "Website Application"; $contact_title = Trim(stripslashes($_POST['contact_title'])); $Firstname = Trim(stripslashes($_POST['Firstname'])); $Surname = Trim(stripslashes($_POST['Surname'])); $DOB = Trim(stripslashes($_POST['DOB'])); $Address1 = Trim(stripslashes($_POST['Address1'])); $Address2 = Trim(stripslashes($_POST['Address2'])); $Postcode = Trim(stripslashes($_POST['Postcode'])); $Telephone = Trim(stripslashes($_POST['Telephone'])); $elig1 = Trim(stripslashes($_POST['elig1'])); $elig2 = Trim(stripslashes($_POST['elig2'])); $elig3 = Trim(stripslashes($_POST['elig3'])); $elig4 = Trim(stripslashes($_POST['elig4'])); $elig5 = Trim(stripslashes($_POST['elig5'])); $elig6 = Trim(stripslashes($_POST['elig6'])); $elig7 = Trim(stripslashes($_POST['elig7'])); $Education = Trim(stripslashes($_POST['Education'])); $Employer_Name = Trim(stripslashes($_POST['Employer_Name'])); $Employer_Address = Trim(stripslashes($_POST['Employer_Address'])); $Manager_Name = Trim(stripslashes($_POST['Manager_Name'])); $Employer_Contact = Trim(stripslashes($_POST['Employer_Contact'])); $Employer_Email = Trim(stripslashes($_POST['Employer_Email'])); $Position_Title = Trim(stripslashes($_POST['Position_Title'])); $Salary = Trim(stripslashes($_POST['Salary'])); $Leaving_Reason = Trim(stripslashes($_POST['Leaving_Reason'])); $Responsibilities = Trim(stripslashes($_POST['Responsibilities'])); $Can_We_Contact = Trim(stripslashes($_POST['Can_We_Contact'])); $Referances = Trim(stripslashes($_POST['Referances'])); $attachment = Trim(stripslashes($_POST['attachment'])); $Position = Trim(stripslashes($_POST['Position'])); $Whyyou = Trim(stripslashes($_POST['Whyyou'])); $attachment_fields[1] = Trim(stripslashes($_POST['attachments'])); $attachment_fields[1]=""; ###################################################### # Make sure all variables have values # if not send to error page # # Could refine this to let user know which # form fields were erroneous # # Lots of info to make then retype the good ones ###################################################### $validationOK=true; if ($contact_title =="choose" OR $EmailFrom)=="" OR $Firstname=="" OR $Surname=="" OR $DOB=="" OR $Address1=="" OR $Address2=="" OR $Postcode=="" OR $Telephone=="" OR $Position==""){ $validationOK=false; } if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=errorapp.php\">"; exit(); } ###################################################### # prepare email body # # took some liberties here to consolidate # and make it easier to see related items ###################################################### $Body .= "Title: " . $contact_title . "\n\n"; $Body .= "First Name: ". $Firstname ."\n\n" . "Surname: " . $Surname . "\n\n"; $Body .= "DOB: " . $DOB ."\n\n"; $Body .= "First Line Of Address: " . $Address1 . "\n\n"; $Body .= "Second Line Of Address: " . $Address2 ."\n\n"; $Body .= "Post Code: " .= $Postcode . "\n\n"; $Body .= "Contact Number: " . $Telephone . "\n\n"; $Body .= "Eligibility Answer 1: " . $elig1 . "\n\n"; $Body .= "Eligibility Answer 2: " . $elig2 . "\n\n"; $Body .= "Eligibility Answer 3: " . $elig3 . "\n\n"; $Body .= "Eligibility Answer 4: " . $elig4 . "\n\n"; $Body .= "Eligibility Answer 5: " . $elig5 . "\n\n"; $Body .= "Eligibility Answer 6: " . $elig6 . "\n\n"; $Body .= "Eligibility Answer 7: " . $elig7 . "\n\n"; $Body .= "Education: " . $Education ."\n\n"; $Body .= "Previous Employer Name: " . $Employer_Name ."\n\n"; $Body .= "Employers Address: " . $Employer_Address . "\n\n"; $Body .= "Manager Name: " . $Manager_Name . "\n\n"; $Body .= "Employer Phone Number: " .$Employer_Contact ."\n\n"; $Body .= "Employer Email: " . $Employer_Email ."\n\n"; $Body .= "Position Held: " . $Position_Title . "\n\n"; $Body .= "Salary: " . $Salary . "\n\n"; $Body .= "Reason For Leaving: " . $Leaving_Reason . "\n\n"; $Body .= "Responsibilities Held: " . $Responsibilities ."\n\n"; $Body .= "Can We Contact Previous Employer: " . $Can_We_Contact . "\n\n"; $Body .= "Referances: " . $Referances . "\n\n"; $Body .= "Position Applying For: " . $Position . "\n\n"; $Body .= "Why The Candidate Is Applying: " . $Whyyou . "\n\n"; ############################################################## # if this is supposed to be a file then you # need its name and location # # Also why are you using an array for it? ############################################################## $Body .= "Attachment: " . $attachment_fields[1] "\n\n"; ############################################################ # Here you are defining a function # # BUT you never call it, WHY? # ############################################################ function getAttachments($attachment_fields, $message, $content_type, $border){ $att_message="This is a multi-part message in MIME format.\r\n"; $att_message.="--{$border}\r\n"; $att_message.=$content_type."\r\n"; $att_message.="Content-Transfer-Encoding: 7bit\r\n\r\n"; $att_message.=$message."\r\n\r\n"; $att_check=preg_split('/,/',$attachment_fields); $att_run=sizeof($att_check); for($i=0;$i<$att_run;$i++){ $fileatt=$_FILES[$att_check[$i]]['tmp_name']; $fileatt_name=$_FILES[$att_check[$i]]['name']; $fileatt_type=$_FILES[$att_check[$i]]['type']; if (is_uploaded_file($fileatt)){ $file=fopen($fileatt,'rb'); $data=fread($file,filesize($fileatt)); fclose($file); $data=chunk_split(base64_encode($data)); $att_message.="--{$border}\n"; $att_message.="Content-Type: {$fileatt_type}; name=\"{$fileatt_name}\"\r\n"; $att_message.="Content-Disposition: attachment; filename=\"{$fileatt_name}\"\r\n"; $att_message.="Content-Transfer-Encoding: base64\r\n\r\n".$data."\r\n\r\n"; } } $att_message.="--{$border}--\n"; return $att_message; } // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=okapp.php\">"; }else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=errorapp.php\">"; } ################################################## # side note # # Since you are using a form, why not store all the data in a database, # upload the file, and just send yourself an email saying some one has added subnitted a form> ########################################## ?> Quote Link to comment Share on other sites More sharing options...
chrismarsden Posted May 9, 2010 Author Share Posted May 9, 2010 Ok, i have put the new code in to the site as your right its much easier to read... how ever as i said i am new to php and have no idea how to post it in to a database let alone retrieve it again... plus that would mean i would need a login script as well and then that just adds to my problems... i have no idea why i dont call the function to be honest, those parts i copied from a different forum (i must have done it badly, unless some very kind person wants to write the script for me (which i would absolutlely be indebted for...) im gonna have to keep looking for a script which i can understand better. Quote Link to comment Share on other sites More sharing options...
litebearer Posted May 9, 2010 Share Posted May 9, 2010 I am old fart LOL and I can do basic php mysql stuff (not with finesse but it works). You need to decide what you want from the user in addition to the form info. What is the file you want then to send supposed to contain? what type of file is it (pic, excel, doc, text etc)? All those issues need to be decided BEFORE you go looking for a script. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.