I have a form that users need to fill out and then attach their resumes. I'm not sure how to send the attachment via email. What I have currently used to work but now that I've changed servers it's no longer working. Is it because there's a newer version of PHP installed on the new server?
Here's my code:
<?php # Script 3.12 - register.php
// Set the page title and include the HTML header.
include ('resume_header.htm');
if (isset($_POST['submit'])) { // Handle the form.
// Check for a first name.
if (strlen($_POST['fname']) > 0) {
$fn = TRUE;
$fname = ($_POST['fname']);
} else {
$fn = FALSE;
echo '<p class="red">You forgot to enter your first name.</p>';
}
// Check for a last name.
if (strlen($_POST['lname']) > 0) {
$ln = TRUE;
$lname = ($_POST['lname']);
} else {
$ln = FALSE;
echo '<p class="red">You forgot to enter your last name.</p>';
}
// Check for an email address.
if (strlen($_POST['email']) > 0) {
$e = TRUE;
$email = ($_POST['email']);
} else {
$e = FALSE;
echo '<p class="red">You forgot to enter your email address.</p>';
}
// Check for phone 1.
if (strlen($_POST['phone']) > 0) {
$p1 = TRUE;
$phone = ($_POST['phone']);
} else {
$p1 = FALSE;
echo '<p class="red">You forgot to enter your phone number.</p>';
}
// Check for address.
if (strlen($_POST['address']) > 0) {
$a1 = TRUE;
$address = ($_POST['address']);
} else {
$a1 = FALSE;
echo '<p class="red">You forgot to enter your address.</p>';
}
// Check for city.
if (strlen($_POST['city']) > 0) {
$c = TRUE;
$city = ($_POST['city']);
} else {
$c = FALSE;
echo '<p class="red">You forgot to enter your city.</p>';
}
// Check for state.
if (strlen($_POST['state']) > 0) {
$s = TRUE;
$state = ($_POST['state']);
} else {
$s = FALSE;
echo '<p class="red">You forgot to enter your state.</p>';
}
// Check for zip.
if (strlen($_POST['zip']) > 0) {
$z = TRUE;
$zip = ($_POST['zip']);
} else {
$z = FALSE;
echo '<p class="red">You forgot to enter your zip code.</p>';
}
// Check for current position.
if (strlen($_POST['position']) > 0) {
$cp= TRUE;
$position = ($_POST['position']);
} else {
$cp = FALSE;
echo '<p class="red">You forgot to enter your current position. <br>If you are not currently employed placed type N/A.</p>';
}
// Check for current employer.
if (strlen($_POST['employer']) > 0) {
$ce= TRUE;
$employer = ($_POST['employer']);
} else {
$ce = FALSE;
echo '<p class="red">You forgot to enter your current position. <br>If you are not currently employed placed type N/A.</p>';
}
// Check for current position.
if (strlen($_POST['desired_pos']) > 0) {
$dp= TRUE;
$desired_pos = ($_POST['desired_pos']);
} else {
$dp = FALSE;
echo '<p class="red">You forgot to enter your desired position.</p>';
}
// Check for years experience.
if (strlen($_POST['yrs_exp']) > 0) {
$ye= TRUE;
$yrs_exp = ($_POST['yrs_exp']);
} else {
$ye = FALSE;
echo '<p class="red">You forgot to enter your years of experience.</p>';
}
// Check for current salary.
if (strlen($_POST['cur_sal']) > 0) {
$cs= TRUE;
$cur_sal = ($_POST['cur_sal']);
} else {
$cs = FALSE;
echo '<p class="red">You forgot to enter your current salary. <br>If you are not currently employed placed type N/A.</p>';
}
// Check for desired salary.
if (strlen($_POST['des_sal']) > 0) {
$ds= TRUE;
$des_sal = ($_POST['des_sal']);
} else {
$ds = FALSE;
echo '<p class="red">You forgot to enter your desired salary.</p>';
}
// Check for relocate.
if($_POST['relocate'] == 'NULL')
{
$relocate = FALSE;
echo '<p class="red">You forgot to choose whether you would prefer to relocate.</p>';
}
else
{
$r= TRUE;
$relocate = ($_POST['relocate']);
}
// Check for relocate area.
if($_POST['relocate'] == 'Yes')
{
if (strlen($_POST['relocate_area']) > 0) {
$ra= TRUE;
$relocate_area = ($_POST['relocate_area']);
} else {
$ra = FALSE;
echo '<p class="red">You forgot enter the city you would like to relocate to.</p>';
}
}else{
$ra= TRUE;
$relocate_area == "N/A";
}
// store the file information to variables for easier access
$tmp_name = $_FILES['filename']['tmp_name'];
$type = $_FILES['filename']['type'];
$name = $_FILES['filename']['name'];
$size = $_FILES['filename']['size'];
// if the upload succeded, the file will exist
if (file_exists($tmp_name)){
// check to make sure that it is an uploaded file and not a system file
if(is_uploaded_file($tmp_name)){
// open the file for a binary read
$file = fopen($tmp_name,'rb');
// read the file content into a variable
$data = fread($file,filesize($tmp_name));
// close the file
fclose($file);
// now we encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}
}else echo '<p class="red">You forgot to upload your resume.</p>';
if ($fn && $ln && $e && p1 && a1 && $c && $s && $z && $cp && $ce && $dp && $ye && $cs && $ds && $r && $data) { // If everything's okay.
// we'll begin by assigning the To address and message subject
$to="me@mywebsite.com";
$subject="www.mywebsite.com - Resume Submitted";
// get the sender's name and email address
// we'll just plug them a variable to be used later
$from = stripslashes($_POST['fname'])." ".stripslashes($_POST['lname'])."<".stripslashes($_POST['email']).">";
// generate a random string to be used as the boundary marker
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
// here we'll hard code a text message
// again, in reality, you'll normally get this from the form submission
$message = "Name: $fname $lname\n\nEmail: $email\n\nPhone: $phone\n\nAddress:\n$address\n$city, $state $zip $country\n\nCurrent Position: $position\n\nDesired Position: $desired_pos\n\nCurrent Employer: $employer\n\nYears of Experience: $yrs_exp\n\nCurrent Salary: $cur_sal\n\nDesired Salary: $des_sal\n\nWilling to Relocate? $relocate\n\nRelocation Preference: $relocate_area";
// now we'll build the message headers
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
// next, we'll build the message body
// note that we insert two dashes in front of the
// MIME boundary when we use it
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
// now we'll insert a boundary to indicate we're starting the attachment
// we have to specify the content type, file name, and disposition as
// an attachment, then add the file content and set another boundary to
// indicate that the end of the file has been reached
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
@mail($to, $subject, $message, $headers);
}
} else { // Display the form.
?>
blah blah
<?php
}
include ('resume_footer.htm'); // Include the HTML footer.
?>