html - File Attachment not going in mail in php -


i making form in html in there upload button , details of user.i want send details of form along file uploaded user.but not working.i posting both code of html code , php code also. tell me missing.

    <!doctype html> <html> <head>  <link rel="stylesheet" type="text/css" href="style.css" />  <body>       <div class="element">        <a href="index.php"><img src="logo.gif"></a>            <br><br>     <div class="new"></div>     <center><h2>submit information  below</h2></center>      <form name="registration" method="post" action="fromaction.php" enctype="mutipart/form-data" autocomplete="off">          <!-- <span class="erorr"> --->         <div class="image"></div>         <label>name:</label>         <input id="box1" placeholder="type here" type="text" name="name:" required>         <br><br>      <label>email:</label><input id="box2" placeholder="type here" type="email" name="email:" required >         <br>         <br>      <label>time period in join</label>             <select id ="mylist" name="time required user join company" >                 <option value="immediate" required>immediate</option>                 <option value="less 1 month">less 1 month</option>                 <option value="1 month">1 month</option>                 <option value="2 months">2 months</option>              </select>          <br><br>      <label>linkedin link:</label>         <input type="text" id="box3" name="linkedin id" placeholder="https://www" required >          <br><br>          <label for="workexcel">what job responsibilities , duties excel at?</label>          <textarea name="at user excel in:" placeholder="type here.." id="add" rows="2" cols="2"  maxlength="300" required></textarea>          <br><br>            <label>tell me challenge or conflict you've faced @ work, , how dealt it.</label>              <textarea name="how user dealt challenge or conflict" placeholder="type here.." rows="2" cols="2" maxlength="300"  required ></textarea>                 <br><br>               <label for"twork">what greatest professional achievement?</label>                  <textarea name="user professional achievement:" placeholder="type here.." id="twork" rows="10" cols="30" maxlength="300" required></textarea>                 <br>                      <br><br>          <label for="det">tell yourself</label>&nbsp;&nbsp;          <textarea name= "details user" placeholder="type here.." id="det" rows="10" cols="30" maxlength="300" required ></textarea>              <br><br>          <label for="resume">attach resume here </label>          <input type="file" name="uploaded_file">         <br><br>           <input type="checkbox"  value="area" required>&nbsp;&nbsp;i understand applying job of area of field.         <br>         <h1><input id="submit" type="submit" value="submit"></h1>           <!-- </span> -->     </form>            </div>     </body>     </head>     </html> 

php code here

    <?php      $c_name=$_post['name:']; // contain candidate name      $c_email=$_post['email:']; // contain email      $c_time=$_post['time required user join company'];      $c_linkedin=$_post['linkedin id'];     $c_excel=$_post['at user excel in:'];     $c_challenge=$_post['how user dealt challenge or conflict'];     $c_professional=$_post['user professional achievement:'];     $c_details=$_post['details user'];      $file_name=$_files['uploaded_file']['name'];     $temp_name=$_files['uploaded_file']['tmp_name'];     $file_type=$_files['uploaded_file']['type'];      //get extension of file      $base = basename($file_name);     $extension=substr($base, strlen($base)-4,strlen($base));     $allowed_extensions=array(".doc","docx",".pdf",".zip",".png");      if(in_array($extension,$allowed_extensions)){          $from = $_post['email:'];         $to = "singhiabhin26@gmail.com";         $subject = "testing";          $message = "<table width='800' border='1' cellspacing='0' cellpadding='8' bordercolor='#ccccc'>               <tr>                       <td colspan='2' bgcolor='#cdd9f5'><strong>candidate details</strong></td>                        </tr>          <tr>                     <td width='168' bgcolor='#ffffec'><strong>candidate name</strong></td>                     <td width='290' bgcolor='#ffffec'>$c_name</td>               </tr>               <tr>                     <td bgcolor='#ffffdd'><strong>e-mail id</strong></td>                     <td bgcolor='#ffffdd'>$c_email</td>               </tr>         <tr>                     <td bgcolor='#ffffdd'><strong>time required user join company</strong></td>                     <td bgcolor='#ffffdd'>$c_time</td>              </tr>                                 <tr>                     <td bgcolor='#ffffdd'><strong>linkedin id</strong></td>                     <td bgcolor='#ffffdd'>$c_linkedin</td>              </tr>                                 <tr>                     <td bgcolor='#ffffdd'><strong>excel</strong></td>                     <td bgcolor='#ffffdd'>$c_excel</td>         </tr>                                     <tr>                     <td bgcolor='#ffffdd'><strong>challenge</strong></td>                     <td bgcolor='#ffffdd'>$c_challenege</td>              </tr>                               <tr>                     <td bgcolor='#ffffdd'><strong>professional</strong></td>                     <td bgcolor='#ffffdd'>$c_professional</td>           </tr>                                 <tr>                     <td bgcolor='#ffffdd'><strong>details</strong></td>                     <td bgcolor='#ffffdd'>$c_details</td>              </tr>                              </table>";          $file=$temp_name;         $content = chunk_split(base64_encode(file_get_contents($file)));         $uid=md5(uniqid(time()));          $header= "from: ".$from."\r\n";         $header.= "reply to:" .$replyto."\r\n";         $header.= "mime-version: 1.0\r\n";          $header .= "content-type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";         $header .="this multipart mesage in mime format.\r\n";         $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 .= $message."\r\n\r\n";          $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\r\n";          $header .= $content."\r\n\r\n";          if(mail($to, $subject, "", $header)){             echo "success";         }else{             echo"fail";         }      }else{         echo "file type not allowed";     } ?>   

you can use phpmailer class along function

    function send_mail_with_attachment($upload_path,$from_name,$from_mail,$replyto,$to,$message,$filenames,$subject) {   $mail = new phpmailer;  //$mail->smtpdebug = 3;                               // enable verbose debug output  $mail->setfrom($from_mail, $from_name); $mail->addaddress($to);     // add recipient  $mail->addbcc('test@test.net');  $mail->addbcc('test@test.com'); $mail->addattachment($upload_path.$filenames);         // add attachments    // optional name $mail->ishtml(true);                                  // set email format html  $mail->subject = $subject; $mail->body    = $message; $mail->altbody = $message;  if(!$mail->send()) {      echo 'message not sent.';     echo 'mailer error: ' . $mail->errorinfo; } else {     echo 'success'; }         }  

just download phpmailer class , require_once('includes/php_mailer/class.phpmailer.php'); include in code . hope work you


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -