Thursday 7 March 2013

mail Attachement in php


<?php
if(isset($_POST['Submit'])) 
   {
    $from=$_POST['uname'];

    $t=$_POST['email'];
    $y=$_POST['post'];
    $rr=$_FILES['file']['strresume'];
    $to="letters/".$_FILES['strresume']['name'];
    move_uploaded_file($_FILES['strresume']['tmp_name'],$to);
    $fileatt = "letters/".$_FILES['strresume']['name']; // Path to the file
    $fileatt_type = "application/octet-stream"; // File Type
    $fileatt_name = "CV_".$_FILES['strresume']['name']; // Filename that will be used for the file as the attachment
    $email_from = $_POST['nume']." ".$_POST['prenume']; // Who the email is from
    $email_subject = "CV".$_FILES['strresume']['name']; // The Subject of the email
    //here you define the body of the message, the message itself
    //you can modify the "post" textfield in sendmail.php to a textarea....
    $email_message ="Name:".$from;
    $email_message.="\r\n";
    //$email_message.=$_POST['uname'];
    $email_message.="Email:".$_POST['email'];
    $email_message.="\r\n";
   //$email_message.="Post Applied For:"
    $email_message.="Post Applied For:". $_POST['post']; // Message that the email has in it
    //here you enter the e-mail address to wich you want the message to be sent
    $email_to = " vivekamcbseschool@gmail.com"; // Who the email is too
    //adds the e-mail address of the sender
    $headers = "From: ".$_POST['email'];
    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
    $headers .= "\nMIME-Version: 1.0\n" .
      "Content-Type: multipart/mixed;\n" .
      " boundary=\"{$mime_boundary}\"";
      $email_message .= "This is a multi-part message in MIME format.\n\n" .
       "--{$mime_boundary}\n" .
        "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
        "Content-Transfer-Encoding: 7bit\n\n" .
        $email_message . "\n\n";

        /********************************************** First File ********************************************/


      //$filleant takes the value of the picture that was jut uploaded with the unique name to the ftp in the www.yourname.com/upload/upload

      $fileatt = "letters/".$_FILES['strresume']['name']; // Path to the file
      $fileatt_type = "application/octet-stream"; // File Type
      //here i made the file that will be sent as attachment to have the name "CV_name_surname.doc" you can make it what format you like,
      //i needed the doc format... and i'll modify this code to accept just doc file later...i'm really tired right now :D
      $fileatt_name = "CV".$_FILES['strresume']['name']; // Filename that will be used for the file as the attachment
      $file = fopen($fileatt,'rb');
      $data = fread($file,filesize($fileatt));
      fclose($file);
      $data = chunk_split(base64_encode($data));
      $email_message .= "--{$mime_boundary}\n" .
      "Content-Type: {$fileatt_type};\n" .
      " name=\"{$fileatt_name}\"\n" .
      //"Content-Disposition: attachment;\n" .
      //" filename=\"{$fileatt_name}\"\n" .
      "Content-Transfer-Encoding: base64\n\n" .
      $data . "\n\n" .
      "--{$mime_boundary}\n";
      unset($data);
      unset($file);
      unset($fileatt);
      unset($fileatt_type);
        unset($fileatt_name);

        /********************************************** End of File Config ********************************************/

      // To add more files just copy the file section again, but make sure they are all one after the other! If they are not it will not work!
      $ok = @mail($email_to, $email_subject, $email_message, $headers);
      if($ok) {?>
      <script>
       alert("Thanks for applying at Vivekam careers! will get back to you soon!");
       window.location="careers.php";
      </script>
      <?php } 
   }

   ?> 





No comments:

Post a Comment