Quick question I'm a front end developer and php isn't my strongest point :) I built this contact form. The problem is php does not seem to be sending the email. Could you help me spot the problem? I'm out of ideas here...
Here is the form:
<form id="job-app" method="post" action="careersss.php" enctype="multipart/form-data">
<div class="container">
<label for="name"> Full Name:
<input type="text" name="name" id="name">
</label>
</div>
<div class="container">
<label for="email"> Email:
<input type="email" name="email" id="email">
</label>
</div>
<div class="container">
<label for="number"> Contact Number:
<input type="text" name="number" id="number">
</label>
</div>
<div class="container">
<label for="resume"> Resume (CV): <span> File types allowed: Word Document or PDF</span>
<input type="file" name="resume" id="resume">
</label>
</div>
<div class="container">
<label for="cover"> Cover Letter:
<textarea name="cover" id="cover"></textarea>
</label>
</div>
<div class="container human">
<label for="human"> Are you human? What is the sum of:
<input type="text" name="human" id="human">
</label>
</div>
<button type="submit">Send</button>
</form>
Here is PHP:
if(isset($_POST) && !empty($_POST)){
if(!empty($_FILES['resume']['name'])){
$file_name = $_FILES['resume']['name'];
$temp_name = $_FILES['resume']['tmp_name'];
$file_type = $_FILES['resume']['type'];
// Get extension of the file
$base = basename($file_name);
$extension = substr($base, strlen($base)-4, strlen($base));
// Only allow these file types
$allowed_extensions = array('.doc', 'docx', '.pdf');
// Check that this file type is allowed
if(in_array($extension, $allowed_extensions)){
// Mail essentials store all variables from
$from = $_POST['email'];
$name = $_POST['name'];
$number = $_POST['number'];
$to = 't.slegaitis@gmail.com';
$subject = 'Job Application ' . date('Y/m/d');
$message = $_POST['cover'];
// Things needed
$file = $temp_name;
$content = chunk_split(base64_encode(file_get_contents($file)));
$uid = md5(uniqid(time()));
// Mail Headers
$header = 'From: '.$from.'\r\n';
$header .= 'Reply-To: '.$from.'\r\n';
$header .= 'MIME-Version: 1.0\r\n';
// Declaring that this email have multiple kinds (i.e Plain text and attachment)
$header .= 'Content-Type: multipart/mixed; boundary=\''.$uid.'\'\r\n\r\n';
$header .= 'This is a multi-part message in MIME Format. \r\n';
// Plain text Part
$header .= '--'.$uid.'\r\n';
$header .= 'Content-type:text/plain; charset=iso-8859-1\r\n';
$header .= 'Content-Transfer-Encoding: 7bit\r\n\r\n';
$header .= 'Name: '.$name.'\r\n';
$header .= 'Contact Number: '.$number.'\r\n';
$header .= 'Email Address: '.$from.'\r\n';
$header .= $message.'\r\n';
// File attachment
$header .= '--'.$uid.'\r\n';
$header .= "Content-Type: ".$file_type."; name=\"".$file_name."\"\r\n";
$header .= 'Content-Transfer-Encoding: base64\r\n';
$header .= 'Content-Disposition: attachment; filename=\''.$file_name.'\'\r\n';
// Send the mail
if(mail($to, $subject, '', $header)){
echo('success');
} else {
echo('fail');
}
} else {
echo('file type not allowed');
}
} else {
echo('No file posted');
}
}
Any help appreciated.