0

I have a html form where i ask my users to fill in their personal and career details and attach their resume. I would like to get those details (form data and the attachment) sent to an email using php.... Any help will be much appreciated....

here is my code for sending mail... Using this i get the file attachment but not the other form data... Pls help where i am going wrong...

<?php
// Settings  -  working good
$name        = "Name goes here";
$email       = "test@gmail.com";
$to          = "$name <$email>";
$from        = "Vijay";
$subject     = "Here is your attachment";
$mainMessage = "Hi, here's the file.";
$attachments = $_FILES['attachment'];

if(empty($_POST['title'])        ||

  empty($_POST['exp'])            ||

  empty($_POST['skill'])         ||

  empty($_POST['qual'])         ||

  empty($_POST['certf'])         ||

  empty($_POST['domain'])        ||

  empty($_POST['fname'])        ||

  empty($_POST['lname'])        ||

  empty($_POST['phone'])        ||

  empty($_POST['email'])        ||

  empty($_POST['csal'])        ||

  empty($_POST['job'])            ||

 // empty($_POST['file'])        ||

  !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))

  {

  echo "No arguments Provided!";



  return false;

  }$title = strip_tags(htmlspecialchars($_POST['title']));

$exp = strip_tags(htmlspecialchars($_POST['exp']));

$skill = strip_tags(htmlspecialchars($_POST['skill']));

$qual = strip_tags(htmlspecialchars($_POST['qual']));

$certf = strip_tags(htmlspecialchars($_POST['certf']));

$domain = strip_tags(htmlspecialchars($_POST['domain']));

$fname = strip_tags(htmlspecialchars($_POST['fname']));

$lname = strip_tags(htmlspecialchars($_POST['lname']));

$phone = strip_tags(htmlspecialchars($_POST['phone']));

$email_address = strip_tags(htmlspecialchars($_POST['email']));

$csal = strip_tags(htmlspecialchars($_POST['csal']));

$job = strip_tags(htmlspecialchars($_POST['job']));



// File
 //Get uploaded file data
    $file_tmp_name    = $_FILES['attachment']['tmp_name'];
    $file_name        = $_FILES['attachment']['name'];
    $file_size        = $_FILES['attachment']['size'];
    $file_type        = $_FILES['attachment']['type'];
    $file_error       = $_FILES['attachment']['error'];

    if($file_error > 0)
    {
        die('Upload error or No files uploaded');
    }
    //read from the uploaded file & base64_encode content for the mail
    $handle = fopen($file_tmp_name, "r");
    $content = fread($handle, $file_size);
    fclose($handle);
    $encoded_content = chunk_split(base64_encode($content));

        $boundary = md5("sanwebe");
        //header
        $headers = "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n";

        //plain text
        $body = "--$boundary\r\n";
        $body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
        $body .= "Content-Transfer-Encoding: base64\r\n\r\n";
        $body .= chunk_split(base64_encode($Message));

        //attachment
        $body .= "--$boundary\r\n";
        $body .="Content-Type: $file_type; name=".$file_name."\r\n";
        $body .="Content-Disposition: attachment; filename=".$file_name."\r\n";
        $body .="Content-Transfer-Encoding: base64\r\n";
        $body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n";
        $body .= $encoded_content;
$Message = "You have received a new resume from your website career application form.\n\n"."Here are the details:\n\n

Title: ".$title."\n
Experience: ".$exp."\n
Skill: ".$skill."\n
Qualification: ".$qual."\n
Domain: ".$domain."\n
First Name: ".$fname."\n
Last Name: ".$lname."\n
Phone: ".$phone."\n
Email: ".$email_address."\n\n

Current Salary: ".$csal."\n\n

Job: ".$job."\n\n";
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatttype};\n" .
" name=\"{$fileattname}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileattname}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"-{$mime_boundary}-\n";
// Send the email
if(mail($to, $subject, $Message, $headers)) {
    echo "The email was sent.";
echo "$fileattname";
}
else {
    echo "There was an error sending the mail.";
}
?>
Praveen
  • 1
  • 4

1 Answers1

0

You want to use proven, well tested libraries like Swiftmailer or Zend\Mail instead of writing the code like you do.

Mike Doe
  • 16,349
  • 11
  • 65
  • 88