Jump to content

Recommended Posts

so i am trying to do an upload attachment with mail says header already output on line 71 and file not uploaded.

 

 

here is the code for file attachment as before i had no header error.

 

 

// if not empty file upload field
if (!empty($_FILES['file_upload']['name'])) {
    $file_name   = $_FILES['file_upload']['name'];
    $tnp_name    = $_FILES['file_upload']['tnp_name'];
    $file_type   = $_FILES['file_upload']['type'];
    // get extension of file 
    $base        = basename($file_name);
    $ext         = substr($base, strlen($base) - 4, strlen($base));
    //allowed extensions
    $allowed_ext = array(
        'jpeg',
        'jpg',
        'gif',
        'png'
    );
    //check if allowed extension
    if (in_array($ext, $allowed_ext)) {
        $file    = $tmp_name;
        $content = chunk_split(base64_encode(file_get_contents($file)));
        $uid     = md5(uniqid(time()));
        //declarinf mutlipart boundary type
        $headers .= "Content-Type: multipart/mixed; boundary=\"" . $uid . "\"\r\n";
        $headers .= "this is a message in multipart MIME format.\r\n";
        //file file_upload
        $headers .= "--" . $uid . "\r\n";
        $headers .= "Content-Type:" . $file_type . "; name=\"" . $file_name . "\"\r\n";
        $headers .= "Content-Transfer-Encoding: Base64\r\n";
        $headers .= "Content-Disposition: file_upload; filename=\"" . $file_name . "\"\r\n";
        $headers .= $content . "\r\n\r\n";
    } else { ///output header error somewhere above or below this line
        echo "File Type Not Allowed!";
    }
} else {
    echo "No File Uploaded!";
}

 

not sure why i get no file uploaded much less output header on line 71

Link to comment
https://forums.phpfreaks.com/topic/266712-help-with-upload-attachment-mail-form/
Share on other sites

It has been my understanding that checking a file's extension is less trust-worthy than checking the type.  I have always checked by type for this reason and use this common array:

$image_types = array('image/bmp','image/gif','image/jpeg', 'image/pjpeg','image/png', 'image/x-png');

 

I'm also confused on how you could get no file uploaded and a header error. your script only does one or the other  :confused:

whole process page:

 

<?php
$name    = "walpole-group.co.uk";
$to      = "****";
//$to  = "****";

/* subject */
$subject = "Walpole Group Male Application Form";
//html encoding unique id
$headers .= "--" . $uid . "\r\n";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$headers .= $message . "\r\n\r\n";
$com12         = trim($_POST["radio1"]);
$comDisplay12  = ($com12 == "Yes" ? " Yes " : " - ");
$com13         = trim($_POST["radio2"]);
$comDisplay13  = ($com13 == "Yes" ? " Yes " : " - ");
$com14         = trim($_POST["radio3"]);
$comDisplay14  = ($com14 == "Yes" ? " Yes " : " - ");
$com16         = trim($_POST["piercings"]);
$comDisplay16  = ($com16 == "Yes" ? " Yes " : " - ");
$com17         = trim($_POST["tattoos"]);
$comDisplay17  = (!empty($com17) ? "$com17" : " - ");
$com18         = trim($_POST["checkbox"]);
$comDisplay18  = (!empty($com18) ? "$com18" : " - ");
$com19         = trim($_POST["checkbox2"]);
$comDisplay19  = (!empty($com19) ? "$com19" : " - ");
$com20         = trim($_POST["checkbox3"]);
$comDisplay20  = (!empty($com20) ? "$com20" : " - ");
$com21         = trim($_POST["checkbox4"]);
$comDisplay21  = (!empty($com21) ? "$com21" : " - ");
$com21a        = trim($_POST["checkbox5"]);
$comDisplay21a = (!empty($com21a) ? "$com21a" : " - ");
$com22         = trim($_POST["checkbox6"]);
$comDisplay22  = (!empty($com22) ? "$com22" : " - ");
$com23         = trim($_POST["checkbox7"]);
$comDisplay23  = (!empty($com23) ? "$com23" : " - ");
// if not empty file upload field
if (!empty($_FILES['file_upload']['name'])) {
    $file_name   = $_FILES['file_upload']['name'];
    $tmp_name    = $_FILES['file_upload']['tmp_name'];
    $file_type   = $_FILES['file_upload']['type'];
   
    //allowed extensions
    $allowed_ext = array('image/bmp','image/gif','image/jpeg', 'image/pjpeg','image/png', 'image/x-png');
    //check if allowed extension
    if (in_array($file_type, $allowed_ext)) {
        $file    = $tmp_name;
        $content = chunk_split(base64_encode(file_get_contents($file)));
        $uid     = md5(uniqid(time()));
        //declarinf mutlipart boundary type
        $headers .= "Content-Type: multipart/mixed; boundary=\"" . $uid . "\"\r\n";
        $headers .= "this is a message in multipart MIME format.\r\n";
        //file file_upload
        $headers .= "--" . $uid . "\r\n";
        $headers .= "Content-Type:" . $file_type . "; name=\"" . $file_name . "\"\r\n";
        $headers .= "Content-Transfer-Encoding: Base64\r\n";
        $headers .= "Content-Disposition: file_upload; filename=\"" . $file_name . "\"\r\n";
        $headers .= $content . "\r\n\r\n";
    } else {
        echo "File Type Not Allowed!";
    }
} else {
    echo "No File Uploaded!";
}
//<hr align="center" width="100"" size="1" noshade color="#3C4B86">
$strBody = "<table width=100% border=0 cellpadding=4 cellspacing=0 bgcolor=#000000 >";
$strBody = $strBody . "<tr><td valign=top><table width=710 cellpadding=0 cellspacing=0 border=0 bordercolor=#FFFFFF>";
$strBody = $strBody . "<tr><td colspan=2 ><font size=3 face=Verdana, Arial, Helvetica, sans-serif color=#FFFFFF><strong>Walpole Group Male Application Form</strong></font><br></td><td> </td></tr>";
$strBody = $strBody . "</tr><tr><td colspan=3><hr align=center width=100% size=1 noshade color=#3C4B86></td>";
//======================model contact info=======================================
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif><b>Model's Information</b></font></td><td> </td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Stage Name:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["stageName"]) . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>First Name:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["firstName"]) . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Surname:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["surName"]) . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>N I No:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["niNo"]) . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Date of birth:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["dob"]) . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Age:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["age"]) . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Star sign:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["star"]) . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Address 1:</font></td>";
$strBody = $strBody . "<td width = 201 colspan=2><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["address1"]) . " </font></td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Address 2:</font></td>";
$strBody = $strBody . "<td width = 201 colspan=2><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["address2"]) . " </font></td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Address 3:</font></td>";
$strBody = $strBody . "<td width = 201 colspan=2><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["address3"]) . " </font></td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Town/City:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["town"]) . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Postcode:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["postcode"]) . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>States:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["states"]) . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Home Telephone No:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["homeNo"]) . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Mobile Telephone No:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["mobileNo"]) . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Email Address:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["email"]) . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Web Address:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["webAddress"]) . " </font></td><td> </td>";
//=====================model physical info========================================
$strBody = $strBody . "</tr><tr><td colspan=3><hr align=center width=100% size=1 noshade color=#3C4B86></td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif><b>Physical Descriptions</b></font></td><td> </td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Height:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["height"]) . "</font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Weight:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["weight"]) . "</font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Suit size:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["suitSize"]) . "</font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Shoe size:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["shoeSize"]) . "</font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Chest size:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["chestSize"]) . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Waist Size:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["waistSize"]) . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Leg Size:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["legSize"]) . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Hair color:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["hairColor"]) . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Length:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["length"]) . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Eyes color:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["eyesColor"]) . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201 valign=top> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Complexion:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["complexion"]) . "</font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201 valign=top> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Ethnic origin:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["ethnicOrigin"]) . "</font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201 valign=top> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Other info:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Do you smoke:" . trim($_POST["radio1"]) . "<BR>Do you drink:" . trim($_POST["radio2"]) . "<BR>Do you drive:" . trim($_POST["radio3"]) . "</font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Piercings:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . $comDisplay16 . " </font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Tattoos:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . $comDisplay17 . " </font></td><td> </td>";
//======================model attributes==============================================
$strBody = $strBody . "</tr><tr><td colspan=3><hr align=center width=100% size=1 noshade color=#3C4B86></td>";
$strBody = $strBody . "</tr><tr><td width=201 valign=top> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif><b>Model's attributes</b></font></td>";
$strBody = $strBody . "</tr><tr><td width=201 valign=top> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Work undertaken</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Fashion:" . $comDisplay18 . "</td><td><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Swimwear:" . $comDisplay19 . "</td></font></tr> ";
$strBody = $strBody . "<tr><td> </td><td><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Nude:" . $comDisplay20 . "</font></td><td><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Boy / Girl Soft:" . $comDisplay21 . "</font></td></tr>";
$strBody = $strBody . "<tr><Td> </td><td><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Boy / Girl XXX:" . $comDisplay21a . "</font></td><td><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Stills:" . $comDisplay22 . "</font></td></tr>";
$strBody = $strBody . "<tr><Td> </td><td><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Video:" . $comDisplay23 . "</font></td><td> </td></tr>";
$strBody = $strBody . "</tr><tr><td width=201> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Previous experiences:</font></td>";
$strBody = $strBody . "<td colspan=2 width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["experience"]) . " </font></td>";
$strBody = $strBody . "</tr><tr><td width=201 valign=top> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Introduce By:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["introduceBy"]) . "</font></td><td> </td>";
$strBody = $strBody . "</tr><tr><td width=201 valign=top> <font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>Date:</font></td>";
$strBody = $strBody . "<td width = 201><font color=#CCCCCC size=2 face=Verdana, Arial, Helvetica, sans-serif>" . trim($_POST["dateTime"]) . "</font></td><td> </td>";
//======================model related info============================================
$strBody = $strBody . "</tr><tr><td colspan=3> </td></tr></table>";
//response.Write(strBody)
$message = "" . $strBody;
if ($Err != 0) {
    print "<script language=javascript>window.open('error.htm', 'winpop', 'scrollbars=no,width=470,height=150,left=250,top=20');window.history.go(-1);</script>";
    //Response.Write "An error occurred: " & Err.Description
} else {
    header("Location: " . "thankyou.php");
}
//message now in multipart header
mail($to, $subject, "", $headers);
?> 

This content comes from lines 10, 11 and 12.

Check your if and else statements b/s comes out nothing from there.

Break down your code line by line and you will find the error.

 

PS. You must re-structure your script

so i crossed these lines out and i get NULL not sure why.....

 

 

//$headers = "MIME-Version: 1.0\r\n";
//$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
//$headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
//$headers .= $message . "\r\n\r\n";

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.