Jump to content

mail sending with attachments


draga

Recommended Posts

i have created  a mail sending code to send mail with attachments, it works perfectly in my server , but didn't work on godaddy server.

 

the error which is returning is :Multiple or malformed newlines found in additional_header

 

hereby am including the code kindly make a suggesion

 

<?php //Template Name: Page app handle ?>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(window).load(function () {
    // Page is fully loaded .. time to fade out your div with a timer ..
    $('#overlay img').fadeOut(5000);
});
</script>


<?php
if(!isset($_POST['fname']))
{
    echo "<script>window.location.href = '".  get_site_url()."/index.php/application/</script>";
}
$ar_modltype = $_POST['model_type'];
$cntmodel = count($ar_modltype);
if($cntmodel>0)
{
for($j=0;$j<$cntmodel;$j++)
{
$modltype = $modltype.", ".$ar_modltype[$j];
}
}

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$gender = $_POST['gender'];
$dob = $_POST['dob'];
$nationality = $_POST['nationality'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
$location = $_POST['location'];
$selvissa = $_POST['selvissa'];
$ethnicity = $_POST['ethnicity'];
$height = $_POST['height'];
$hips = $_POST['hips'];
$hair_color1 = $_POST['hair_color'];
if($hair_color1=="Other")
{
    $hair_color=$_POST['s_hair_color'];
}
else
{
    $hair_color=$hair_color1;
}
$chest = $_POST['chest'];
$shoe = $_POST['shoe'];
$eye_color = $_POST['eye_color'];
$waist = $_POST['waist'];
$hair = $_POST['hair'];

/*if (isset($_POST['health_card'])) {
   $healthcard="Yes";
}
else
{
    $healthcard="No";
}*/


if (isset($_POST['driving_license'])) {
    $driving_license="Yes";
}
else
{
    $driving_license="No";
}

if (isset($_POST['portfolio'])) {
    $portfolio="Yes";
}
else
{
    $portfolio="No";
}
/*if (isset($_POST['duty_free'])) {
    $duty_free="Yes";
}
else
{
    $duty_free="No";
}*/

$ar_availability = $_POST['availability'];
$cntavail = count($ar_availability);
if($cntavail>0)
{
for($i=0;$i<$cntavail;$i++)
{
$availability = $availability.", ".$ar_availability[$i];
}
}

$langhid = $_POST['langhid'];

$experience = $_POST['experience'];

//$prvs_events = $_POST['prvs_events'];

$avg_pay = $_POST['avg_pay'];

$remarks = $_POST['remarks'];



   $modltype1 = str_replace(',', '/', $modltype);

//mailing
   $loop = new WP_Query(array('post_type'=>'mainpoint_news','orderby'=>'id','order'=>'asc','posts_per_page' => 1));
    
    if ($loop->have_posts()){
        
        
            
        
        $x=1;
        
        
        while($loop->have_posts()){
        $loop->the_post();
                
      $meta=  get_post_custom(get_the_ID());   
      
       $strTo= esc_attr($meta['mainpoint_newsarea'][0]);
     // $to="abu";
      //echo $to;
       //exit();
}}
  
    $strSubject = substr($modltype1,1).":".$fname;
         
    //$strMessage = $msg;

    //*** Uniqid Session ***//
    $strSid = md5(uniqid(time()));

    $strHeader = "";
    $strHeader .= "From:".trim($fname)."<".$email.">\nReply-To:".$email."";

    $strHeader .= "MIME-Version: 1.0\n";
    $strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
    $strHeader .= "This is a multi-part message in MIME format.\n";

    $strHeader .= "--".$strSid."\n";
    $strHeader .= "Content-type: text/html; charset=iso-8859-1\n";
    $strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
    $strHeader .= "<h1>Contact Details</h1>\n";
        $strHeader .= "<label style='font-size:17px'><b>Categories : </b></label><label style='font-size:16px'><b>".substr($modltype,1)."</b></label><br>";        
        $strHeader .= "<label style='font-size:17px'><b>First Name : </b></label><label style='font-size:16px'><b>".$fname ."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Last Name : </b></label><label style='font-size:16px'><b>".$lname ."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Gender : </b></label><label style='font-size:16px'><b>".$gender."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Date of Birth : </b></label><label style='font-size:16px'><b>".$dob ."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Nationality : </b></label><label style='font-size:16px'><b>".$nationality ."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Mobile  : </b></label><label style='font-size:16px'><b>".$mobile ."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Email  :  </b></label><label style='font-size:16px'><b>".$email ."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Location  :  </b></label><label style='font-size:16px'><b>".$location ."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Visa Type :  </b></label><label style='font-size:16px'><b>".$selvissa ."</b></label><br>";        
         $strHeader .= "<h1>Personal Details</h1>";
        $strHeader .= "<label style='font-size:17px'><b>Ethnicity  : </b></label><label style='font-size:16px'><b>".$ethnicity ."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Height  : </b></label><label style='font-size:16px'><b>".$height ."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Hips  : </b></label><label style='font-size:16px'><b>".$hips ."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Hair Color  :  </b></label><label style='font-size:16px'><b>".$hair_color ."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Bust/Chest(Inches) :  </b></label><label style='font-size:16px'><b>".$chest."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Shoe Size(cm)  : </b></label><label style='font-size:16px'><b>".$shoe ."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Eye Color  :  </b></label><label style='font-size:16px'><b>".$eye_color  ."</b></label><br>";
         $strHeader .= "<label style='font-size:17px'><b>Waist(Inches) :  </b></label><label style='font-size:16px'><b>".$waist ."</b></label><br>";
       $strHeader .= "<label style='font-size:17px'><b>Hair Type  :   </b></label><label style='font-size:16px'><b>".$hair ."</b></label><br>";
       $strHeader .= "<h1>Additional Information </h1>";
        //$strHeader .= "<label style='font-size:17px'><b>Occupational Health Card :  </b></label><label style='font-size:16px'><b>".$healthcard."</b></label><br>";
       $strHeader .= "<label style='font-size:17px'><b>Driving License :  </b></label><label style='font-size:16px'><b>".$driving_license."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Portfolio : </b></label><label style='font-size:16px'><b>".$portfolio."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Availability : </b></label><label style='font-size:16px'><b>".substr($availability,1)."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Languages : </b></label><label style='font-size:16px'><b>".substr($langhid, 1)."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Years of Experience : </b></label><label style='font-size:16px'><b>".$experience."</b></label><br>";
        //$strHeader .= "<label style='font-size:17px'><b>Previous events : </b></label><label style='font-size:16px'><b>".$prvs_events."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Avg Hourly/Daily Rate(In AED) : </b></label><label style='font-size:16px'><b>".$avg_pay."</b></label><br>";
       // $strHeader .= "<label style='font-size:17px'><b>Dubai Duty Free License : </b></label><label style='font-size:16px'><b>".$duty_free."</b></label><br>";
        $strHeader .= "<label style='font-size:17px'><b>Remarks : </b></label><label style='font-size:16px'><b>".$remarks."</b></label>\n\n";
    //*** Attachment ***//
    for($i=0;$i<count($_FILES["model_photos"]["name"]);$i++)
    {
        if($_FILES["model_photos"]["name"][$i] != "")
        {
            $strFilesName = $_FILES["model_photos"]["name"][$i];
            $strContent = chunk_split(base64_encode(file_get_contents($_FILES["model_photos"]["tmp_name"][$i])));
            $strHeader .= "--".$strSid."\n";
            $strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
            $strHeader .= "Content-Transfer-Encoding: base64\n";
            $strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
            $strHeader .= $strContent."\n\n";
        }
    }
    
    for($i=0;$i<count($_FILES["passport"]["name"]);$i++)
    {
        if($_FILES["passport"]["name"][$i] != "")
        {
            $strFilesName = $_FILES["passport"]["name"][$i];
            $strContent = chunk_split(base64_encode(file_get_contents($_FILES["passport"]["tmp_name"][$i])));
            $strHeader .= "--".$strSid."\n";
            $strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
            $strHeader .= "Content-Transfer-Encoding: base64\n";
            $strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
            $strHeader .= $strContent."\n\n";
        }
    }
    if($portfolio=="Yes")
    {
    if($_FILES["portfolio_already"]["name"] != "")
        {
            $strFilesName = $_FILES["portfolio_already"]["name"];
            $strContent = chunk_split(base64_encode(file_get_contents($_FILES["portfolio_already"]["tmp_name"])));
            $strHeader .= "--".$strSid."\n";
            $strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
            $strHeader .= "Content-Transfer-Encoding: base64\n";
            $strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
            $strHeader .= $strContent."\n\n";
        }
    }
    
    for($i=0;$i<count($_FILES["resume"]["name"]);$i++)
    {
        if($_FILES["resume"]["name"][$i] != "")
        {
            $strFilesName = $_FILES["resume"]["name"][$i];
            $strContent = chunk_split(base64_encode(file_get_contents($_FILES["resume"]["tmp_name"][$i])));
            $strHeader .= "--".$strSid."\n";
            $strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
            $strHeader .= "Content-Transfer-Encoding: base64\n";
            $strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
            $strHeader .= $strContent."\n\n";
        }
    }
    
    echo $strHeader    ;    
    if(trim($fname)!='' && trim($gender)!='')    
    {
    
    if(@mail($strTo,$strSubject,"null",$strHeader))
    {
    
        echo "<script>window.location.href = '".  get_site_url()."/index.php/application/?suc=1'</script>";
    }
    else
    {
            
        echo "<script>window.location.href = '".  get_site_url()."/index.php/application/?suc=0'</script>";
    }
    }
    else
    {
        echo "<script>window.location.href = '".  get_site_url()."/index.php/application/?suc=0'</script>";
    }
    

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.