Jump to content

Form image attachment script attaches wrong image


thighmister

Recommended Posts

I am trying to create a form that allows the user to send an image along with other info.

 

Here is the form:  http://rufushale.com/feedback.php

 

The problem is that it sends an image called "pic.jpg" (a file so named happens to be in the main directory on my server), because the script below includes the following lines:

 

$fileatt      = "pic.jpg"; //name of the attachment
$fileatt_type = "image/jpeg"; //mime type this has to be right for the particular attachment
$fileatt_name = "pic.jpg"; //what you want to name the attachment in the email

 

When I leave out "pic.jpg" in the script it sends nothing.

 

How do I get it to send the image that is chosen via the form?

 

Here is the rest of feedout.php:

 

<?php

$package = $_POST['package'];
$background1 = $_POST['background1'];
$bgside1 = $_POST['bgside1'];
$background2 = $_POST['background2'];
$bgside2 = $_POST['bgside2'];
$verse1 = $_POST['verse1'];
$verseside1 = $_POST['verseside1'];
$verse2 = $_POST['verse2'];
$verseside2 = $_POST['verseside2'];
$poem1 = $_POST['poem1'];
$poemside1 = $_POST['poemside1'];
$poem2 = $_POST['poem2'];
$poemside2 = $_POST['poemside2'];
$verseside1 = $_POST['verseside1'];
$quantity = $_POST['quantity'];
$plastic = $_POST['plastic'];
$highgloss = $_POST['highgloss'];
$matte = $_POST['matte'];
$tassle = $_POST['tassle'];
$font = $_POST['font'];
$poem = $_POST['poem'];
$verse = $_POST['verse'];
$background = $_POST['background'];
$idis = $_POST['idis'];
$httpagent = $_POST['httpagent'];
$httpref = $_POST['$httpref'];
$nameis = $_POST['nameis'];
$visitormail = $_POST['visitormail'];
$obituary1 = $_POST['obituary1'];
$obituary2 = $_POST['obituary2'];
$obitside1 = $_POST['obitside1'];
$obitside2 = $_POST['obitside2'];
$phpform = $_POST['phpform'];
$htmlform = $_POST['htmlform'];


if (eregi('http:', $obituary)) { die ("Do NOT try that! ! "); }

if((!$visitormail == "") && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$tellem = "<h2>Order was NOT submitted</h2>\n";
}

if(empty($nameis) || empty($idis) || empty($visitormail)) {
echo "<h2>Please use the back button on your browser and make sure the name, ID#, and email fields are complete.</h2>\n";
}

echo $tellem;

if ($plastic == "y") {
$req1 = "Plastic Sleeve \n" ;
}

if ($highgloss == "y") {
$req2 = "High Gloss \n";
}
if ($matte == "y") {
$req3 = "Matte \n";
}

$req = $req1 . $req2 . $req3;

$todayis = date("l, F j, Y, g:i a") ;

$attn = $attn;
$subject = $attn;

$obituary = stripcslashes($obituary);

$message = " $todayis [EST] \n
ID: $idis \n
From: $nameis ($visitormail)\n
Quantity: $quantity \n
Background: $background1 (Side: $bgside1) \n
Background: $background2 (Side: $bgside2) \n
Obituary: $obituary1 \n
Tassle: $tassle \n
Verse: $verse1 (Side: $verseside1) \n
Verse: $verse2 (Side: $verseside2) \n
Poem: $poem1 (Side: $poemside1) \n
Poem: $poem2 (Side: $poemside2) \n
Font: $font \n
Sleeve/Finish: $req \n
Package: $package \n
";

//*******************************
//define the proposed attachment
//********************************
$fileatt      = "pic.jpg"; //name of the attachment
$fileatt_type = "image/jpeg"; //mime type this has to be right for the particular attachment
$fileatt_name = "pic.jpg"; //what you want to name the attachment in the email

// Read the file to be attached ('rb' = read binary)
  $file = fopen($fileatt,'rb');
  $data = fread($file,filesize($fileatt));
  fclose($file);
  
//*******************************
//compile the multipart email message
//********************************

// Generate a boundary string
  $semi_rand = md5(time());
  $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";


// Add the headers for a file attachment
  $headers .= "\nMIME-Version: 1.0\n" .
              "Content-Type: multipart/mixed;\n" .
              " boundary=\"{$mime_boundary}\"";

// Add a multipart boundary above the plain message
  $message = "This is a multi-part message in MIME format.\n\n" .
             "--{$mime_boundary}\n" .
             "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
             "Content-Transfer-Encoding: 7bit\n\n" .
             $message . $body_text . "\n\n";

// Base64 encode the file data
  $data = chunk_split(base64_encode($data));
  
// Add file attachment to the message
  $message .= "--{$mime_boundary}\n" .
              "Content-Type: {$fileatt_type};\n" .
              " name=\"{$fileatt_name}\"\n" .
              "Content-Transfer-Encoding: base64\n\n" .
              $data . "\n\n" ;


$from = "From: $visitormail\r\n";

mail("[email protected]", $subject, $message, $from);



$screenout = str_replace("\n", "<br/>", $message);
?>


<?php echo $screenout ?>

</p>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.