Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/purvgwtw/public_html/tutorials/common.php on line 7
PHP sent mail example with header MIME type
Sponsered Links
Categories
Sponsered Links

PHP sent mail example with header MIME type

PHP sent mail example with header MIME type. In this example we sent a complete form in a message with mail subjects, MAIL HEADERS with attachment, and using a method to help avoid spam.

<?php
                     
    $fname=ucfirst($_REQUEST["fname"]);
    $lname=ucfirst($_REQUEST["lname"]);   
    $email=$_REQUEST["email"];  
 
      $phone=$_REQUEST["fphone"];
       if($phone != ""){ $strno=$phone; } else { $strno="-"; } 

       $sphone=$_REQUEST["sphone"];
       if($sphone != ""){ $sstrno=$sphone; } else { $sstrno="-"; } 
   
    $address1=ucfirst($_REQUEST["address1"]);
    $address2=ucfirst($_REQUEST["address2"]);
    $city=ucfirst($_REQUEST["city"]);
    $country=ucfirst($_REQUEST["country"]);
    $contact_comment=ucfirst($_REQUEST["contact_comment"]);
    $area_experties=ucfirst($_REQUEST["area_experties"]);
    $carrer_level=ucfirst($_REQUEST["carrer_level"]);
    $job_type=ucfirst($_REQUEST["job_type"]);
    $availablity=ucfirst($_REQUEST["availablity"]);
    $details=ucfirst($_REQUEST["details"]);


    $strresume_name=$_FILES["strresume"]["name"];
    $strresume_type=$_FILES["strresume"]["type"];
    $strresume_size=$_FILES["strresume"]["size"];
    $strresume_temp=$_FILES["strresume"]["tmp_name"];
 
    if($strresume_type=="application/octet-stream" or $strresume_type=="text/plain" or $strresume_type=="application/msword")
    {
  
      $message==$message .= '<table cellspacing="0" cellpadding="8" border="0" width="400">
              <tr>
                <td colspan="2"></td>
            </tr>
            <tr bgcolor="#eeeeee">
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Frist Name</strong></td>
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$fname.'</td>
            </tr>
           

             <tr bgcolor="#eeeeee">
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Last Name</strong></td>
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$lname.'</td>
            </tr>

              <tr bgcolor="#eeeeee">
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Email</strong></td>
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$email.'</td>
            </tr>


            <tr bgcolor="#eeeeee">
              <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Frist Contact No.</strong></td>
              <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$strno.'</td>
            </tr>

            <tr bgcolor="#eeeeee">
              <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Second Contact No.</strong></td>
              <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$sstrno.'</td>
            </tr>
           
            <tr bgcolor="#eeeeee">
              <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Address1</strong></td>
              <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$address1.'</td>
              </tr>

            <tr bgcolor="#eeeeee">
              <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Address2</strong></td>
              <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$address1.'</td>
              </tr>
          
            <tr bgcolor="#eeeeee">
              <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>City</strong></td>
              <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$city.'</td>
              </tr>
            
            <tr bgcolor="#eeeeee">
              <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Country</strong></td>
              <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$country.'</td>
              </tr>
           
            <tr bgcolor="#eeeeee">
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Contact Comment</strong></td>
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$contact_comment.'</td>
            </tr>

              <tr bgcolor="#eeeeee">
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Area Of Experties</strong></td>
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$area_experties.'</td>
            </tr>


              <tr bgcolor="#eeeeee">
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Career Level</strong></td>
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$carrer_level.'</td>
            </tr>


             <tr bgcolor="#eeeeee">
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Job Type</strong></td>
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$job_type.'</td>
            </tr>

             <tr bgcolor="#eeeeee">
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Availablity</strong></td>
                <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$availablity.'</td>
            </tr>
          
            <tr bgcolor="#eeeeee">
                <td colspan="2" style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Details</strong></td>
            </tr>              
            <tr bgcolor="#eeeeee">
                <td colspan="2" style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$details.'</td>
            </tr>              
                                  
         </table>';

    // MAIL SUBJECT

    $subject = "Mail For ".$area_experties;
  
    // TO MAIL ADDRESS
  
  
    $to="varun@homedmartstores.com";

/*
    // MAIL HEADERS
                      
    $headers  = "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\n";
    $headers .= "From: Name <name@name.com>\n";

*/

    // MAIL HEADERS with attachment

    $fp = fopen($strresume_temp, "rb");
    $file = fread($fp, $strresume_size);

    $file = chunk_split(base64_encode($file));
    $num = md5(time());
  
        //Normal headers

       $headers  = "From:".$email."\r\n";
       $headers  .= "MIME-Version: 1.0\r\n";
       $headers  .= "Content-Type: multipart/mixed;";
       $headers  .= "boundary=".$num."\r\n";
       $headers  .= "--$num\r\n";

        // This two steps to help avoid spam  

    $headers .= "Message-ID: <".gettimeofday()." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n";
    $headers .= "X-Mailer: PHP v".phpversion()."\r\n";        

        // With message
      
       $headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
       $headers .= "Content-Transfer-Encoding: 8bit\r\n";
       $headers .= "".$message."\n";
       $headers .= "--".$num."\n";

        // Attachment headers

       $headers  .= "Content-Type:".$strresume_type." ";
       $headers  .= "name=\"".$strresume_name."\"r\n";
       $headers  .= "Content-Transfer-Encoding: base64\r\n";
       $headers  .= "Content-Disposition: attachment; ";
       $headers  .= "filename=\"".$strresume_name."\"\r\n\n";
       $headers  .= "".$file."\r\n";
       $headers  .= "--".$num."--";


    // SEND MAIL
      
     mail($to, $subject, $message, $headers);
  
     fclose($fp);

   header('Location:careersfrom.php?msgyes');
}
else
    {
       header('Location:careersfrom.php?msgno');
   }

?>

Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2014 PURVACOMPUTERS.COM All Right Reserved