email - Attaching an uploaded image in PHP mail -


hi ladies , gentlemen hoping able me this.

i have created web form people can enter registration information , upload image our server photo contest. uploader works great , email gets sent registration information having hard time getting uploaded image attach email. hoping able me figure out. form , processor page located in same directory , image placed in subfolder called upload. here have far not work attaching image. give me error:

    <?php   if ((($_files["file"]["type"] == "image/jpeg")    || ($_files["file"]["type"] == "image/pjpeg"))    && ($_files["file"]["size"] < 2000000))  { if ($_files["file"]["error"] > 0) { echo "error: " . $_files["file"]["error"] . "<br />"; } else { echo "upload: " . $_files["file"]["name"] . "<br />"; echo "type: " . $_files["file"]["type"] . "<br />"; echo "size: " . ($_files["file"]["size"] / 1024) . " kb<br />";   if (file_exists("upload/" . $_files["file"]["name"]))   {   echo $_files["file"]["name"] . " exists. ";   }   else   {   move_uploaded_file($_files["file"]["tmp_name"],   "upload/" . $_files["file"]["name"]);   echo "stored in: " . "upload/" . $_files["file"]["name"];   echo "\nfile submitted.";   } } } else {   echo "invalid file";  }           // mailing here          $fields = array('name','address','city','state','zip','phone','photo','location');          //$to = "cboyd@dacc.edu";         $to2 = "ampeck@earthlink.net";         $subject = "sustainability photo contest";         $headers =  "mime-version: 1.0\r\n" ."content-type: multipart/mixed; boundary=\"$bound_text\"";          $headers .='content-type: image/jpeg; charset=iso-8859-1' . php_eol;         $headers .= "from: noreply@dacc.edu\r\n" . "x-mailer: php";         $bound_text =   "daccreport";  $bound =   "--".$bound_text."\r\n";  $bound_last =  "--".$bound_text."--\r\n";      $message =    "if can see mime client doesn't accept mime types!\r\n" .$bound;    $message .=   "content-type: image/jpeg; charset=\"iso-8859-1\"\r\n" ."content-transfer-encoding: 7bit\r\n\r\n" ."photo contest entry\r\n" .$bound;      $file =   file_get_contents($_files["file"]["name"]);   $message .=    "content-type: image/jpeg; name="($_files["file"]["name"])"\r\n" ."content-transfer-encoding: base64\r\n" ."content-disposition: attachment; file="($_files["file"]["name"])"\r\n" ."\r\n" .chunk_split(base64_encode($file)) .$bound_last;           $greet = "the following submitted on " . date("f j, y, g:i a") . "<p>";          $body = $greet;         //$cn = 1;          foreach($fields $efield) {             if(isset($_post[$efield])) {                   if($efield == "name") {                     $body.= "<strong>name: </strong>" . $_post[$efield] . "<p>";                 } elseif($efield == "address") {                     $body.= "<strong>address:</strong> " . $_post[$efield] . "<p>";                 } elseif($efield == "city") {                     $body.= "<strong>city:</strong> " . $_post[$efield] . "<p>";                 } elseif ($efield == "state") {                     $body.= "<strong>state: </strong>" . $_post[$efield] . "<p>";                 } elseif ($efield == "phone") {                     $body.= "<strong>daytime phone number: </strong>" . $_post[$efield] . "<p>";                 } elseif ($efield == "photo") {                     $body.= "<strong>name of photo: </strong>" . $_post[$efield] . "<p>";                 } elseif ($efield == "location") {                     $body.= "<strong>location photo taken:</strong> " . $_post[$efield] . "<p>";                  }             }         }          //mail($to, $subject, $body, $headers);         mail($to2, $subject, $body, $headers);          ?> 

here solution came with. took little finessing based on upload code , attaching files information. plus ran problem headers, managed work , works well.

    <?php  if ((($_files["file"]["type"] == "image/jpeg")  || ($_files["file"]["type"] == "image/pjpeg"))  && ($_files["file"]["size"] < 2000000))    {    if ($_files["file"]["error"] > 0)      {      echo "error: " . $_files["file"]["error"] . "<br />";      }    else      {      echo "upload: " . $_files["file"]["name"] . "<br />";      echo "type: " . $_files["file"]["type"] . "<br />";      echo "size: " . ($_files["file"]["size"] / 1024) . " kb<br />";        if (file_exists("upload/" . $_files["file"]["name"]))        {        echo $_files["file"]["name"] . " exists. ";        }      else        {        move_uploaded_file($_files["file"]["tmp_name"],        "upload/" . $_files["file"]["name"]);        echo "stored in: " . "upload/" . $_files["file"]["name"];        echo "<br> file submitted.";        }      }    }  else    {    echo "invalid file";    }               // mailing here      $filename = "upload/" . $_files["file"]["name"];  ;         $to3 =       $to4 =   $subject =     'sustainability photo contest';  $bound_text =  "dacc1231";  $bound =   "--".$bound_text."\r\n";  $bound_last =  "--".$bound_text."--\r\n";   $headers =     "mime-version: 1.0\r\n" ."content-type: multipart/mixed; boundary=\"$bound_text\"". php_eol;  $headers .=    "from: noreply@dacc.edu\r\n";     $fields = array('name','address','city','state','zip','phone','photo','location');          $greet = "the following submitted on " . date("f j, y, g:i a") . "<p>";          $body = $greet;         //$cn = 1;          foreach($fields $efield) {             if(isset($_post[$efield])) {                   if($efield == "name") {                     $body.= "<strong>name: </strong>" . $_post[$efield] . "<p>";                 } elseif($efield == "address") {                     $body.= "<strong>address:</strong> " . $_post[$efield] . "<p>";                 } elseif($efield == "city") {                     $body.= "<strong>city:</strong> " . $_post[$efield] . "<p>";                 } elseif ($efield == "state") {                     $body.= "<strong>state: </strong>" . $_post[$efield] . "<p>";                 } elseif ($efield == "phone") {                     $body.= "<strong>daytime phone number: </strong>" . $_post[$efield] . "<p>";                 } elseif ($efield == "photo") {                     $body.= "<strong>name of photo: </strong>" . $_post[$efield] . "<p>";                 } elseif ($efield == "location") {                     $body.= "<strong>location photo taken:</strong> " . $_post[$efield] . "<p>";                  }             }         }   $message =     "if can see mime client doesn't accept mime types!\r\n" .$bound;   $message .=    "content-type: text/html; charset=\"iso-8859-1\"\r\n" ."content-transfer-encoding: 7bit\r\n\r\n" ."here submission photo contest\r\n" .$body ."\r\n"  .$bound;       $file =     file_get_contents($filename);    $message .=    "content-type: image/jpg; name=\"".$filename."\"\r\n" ."content-transfer-encoding: base64\r\n" ."content-disposition: attachment; file=\"".$filename."\"\r\n" ."\r\n" .chunk_split(base64_encode($file)) .$bound_last;   if(mail($to3, $subject, $message,  $headers)  &&  mail($to4, $subject, $message,$headers ))  {  echo '<br> mail sent';  } else {  echo '<br> mail failed';  }              ?> 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -