Jump to content

Email attachment 2nd file is not showing up in the email


Recommended Posts

<?php

  $Name=$_POST["Name"];

  $Address=$_POST["Address"];

  $City=$_POST["City"];

  $State=$_POST["State"];

  $Zip=$_POST["Zip"];

  $Phone=$_POST["Phone"];

  $Cell=$_POST["Cell"];

  $Fax=$_POST["Fax"];

  $Email=$_POST["Email"];

 

  $DogsName=$_POST["DogsName"];

  $DogsAge=$_POST["DogsAge"];

  $Breed=$_POST["Breed"];

  $DogsWeight=$_POST["DogsWeight"];

  $DogsSex=$_POST["DogsSex"];

  $SpayedNeutered=$_POST["SpayedNeutered"];

 

  $Medications=$_POST["Medications"];

  $Diet=$_POST["Diet"];

  $Exercise=$_POST["Exercise"];

  $Story=$_POST["Story"];

 

  $Diabetes=$_POST["Diabetes"];

  $KidneyLiver=$_POST["KidneyLiver"];

  $FoodAllergies=$_POST["FoodAllergies"];

  $HeartDisease=$_POST["HeartDisease"];

  $Other=$_POST["Other"];

 

  $entrant = sprintf("Please Enter Us Into the Healthiest Hound Contest: %s\n\nName: %s\n\nAddress: %s %s\n\nPhone:%s\n\nCell Phone: %s\n\nEmail: %s\n",

    $Name, $Address, $City, $State, $Zip, $Phone, $Cell, $Email);

 

  $hound = sprintf("Description of Hound to Be Entered:\nName: %s, Age: %s, Breed: %s, Weight: %s, Sex: %s, Spayed/Neutered: %s\n\n\n",

    $DogsName, $DogsAge, $Breed, $DogsWeight, $DogsSex, $SpayedNeutered);

           

  $details = sprintf("Medications:\n\n%s\n\nDiet:\n\n%s\n\nExercise: %s\n\nStory: %s\n\n\n",

    $Medications, $Diet, $Exercise, $Story);

 

  $ailments = sprintf("Diabetes: %s\n\nKidney/Liver Disease: %s\n\nFood Allergies: %s\n\nHeart Disease: %s\n\nOther: %s\n\n",

    $Diabetes, $KidneyLiver, $FoodAllergies, $HeartDisease, $Other);

 

  $body1 = sprintf("%s\n%s\n%s\n%s\n",

    $entrant, $hound, $details, $ailments);

 

  $body2 = sprintf("Thank You For Applying to Our Curb Your Pouch Contest\nWe will get back with you in several working days\nHere is the info you sent us.  Thanks Again!!\n\n%s", $body1);

 

  $to = "$Name <$Email>";

  $from = "email@email.com";

  $subject = "Application Curb Your Pouch";

 

 

  if ($_FILES["Picture1"]["error"] > 0)

    {

    echo "Return Code: " . $_FILES["Picture1"]["error"] . "<br />";

    }

  else

    if (is_uploaded_file($_FILES['Picture1']['tmp_name']))

    {

    echo "Upload: " . $_FILES["Picture1"]["name"] . "<br />";

    echo "Type: " . $_FILES["Picture1"]["type"] . "<br />";

    echo "Size: " . ($_FILES["Picture1"]["size"] / 1024) . " Kb<br />";

    echo "Temp file: " . $_FILES["Picture1"]["tmp_name"] . "<br />";   

    }

    else

    {

      echo "File Not Uploaded: ";

      echo "filename '". $_FILES['Picture1']['tmp_name'] . "'.";

    }

 

  if ($_FILES["Picture2"]["error"] > 0)

    {

    echo "Return Code: " . $_FILES["Picture2"]["error"] . "<br />";

    }

  else

    if (is_uploaded_file($_FILES['Picture2']['tmp_name']))

    {

    echo "Upload: " . $_FILES["Picture2"]["name"] . "<br />";

    echo "Type: " . $_FILES["Picture2"]["type"] . "<br />";

    echo "Size: " . ($_FILES["Picture2"]["size"] / 1024) . " Kb<br />";

    echo "Temp file: " . $_FILES["Picture2"]["tmp_name"] . "<br />";   

    }

    else

    {

      echo "File Not Uploaded: ";

      echo "filename '". $_FILES['Picture2']['tmp_name'] . "'.";

    }

 

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

  $headers .= "Bcc: hhstables@hhstables.com"; 

 

  $semi_rand = md5( time() );

  $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

   

  $headers .= "\nMIME-Version: 1.0\n" .

                    "Content-Type: multipart/mixed;\n" .

                    " boundary=\"{$mime_boundary}\"";

   

  $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" .

                $body2 . "\n\n";

 

  $fileatt = $_FILES["Picture1"]["tmp_name"];

  $fileattname = "sideview.jpg";

  $fileatttype = $_FILES["Picture1"]["type"];

 

  $file = fopen( $fileatt, 'rb' );

  $data = fread( $file, $_FILES["Picture1"]["size"]);

  fclose($file);

 

  $data = chunk_split(base64_encode($data));

  $message .= "--{$mime_boundary}\n" .

                "Content-Type: {$fileatttype};\n" .

                " name=\"{$fileattname}\"\n" .

                "Content-Disposition: attachment;\n" .

                " filename=\"{$fileattname}\"\n" .

                "Content-Transfer-Encoding: base64\n\n" .

                $data . "\n\n" .

                "--{$mime_boundary}--\n";

 

  unset($data);

  unset($file);

  unset($fileatt);

  unset($fileatttype);

  unset($fileattname);

 

  $fileatt2 = $_FILES["Picture2"]["tmp_name"];

  $fileatt2name = "topview.jpg";

  $fileatt2type = $_FILES["Picture2"]["type"];

 

  $file2 = fopen( $fileatt2, 'rb' );

  $data2 = fread( $file2, $_FILES["Picture2"]["size"]);

  fclose($file2);   

 

  $data2 = chunk_split(base64_encode($data2));

  $message .= "Content-Type: {$fileatttype};\n" .

                " name=\"{$fileattname}\"\n" .

                "Content-Disposition: attachment;\n" .

                " filename=\"{$fileattname}\"\n" .

                "Content-Transfer-Encoding: base64\n\n" .

                $data2 . "\n\n" . 

                "--{$mime_boundary}--\n";

 

  unset($data2);

  unset($file2);

  unset($fileatt2);

  unset($fileatt2type);

  unset($fileatt2name);[/font]

if( mail( $to, $subject, $message, $headers ) )

  echo "<p>The email was sent.</p>";

else

  echo "<p>There was an error sending the mail.</p>";

 

 

 

?>

 

I get all the information need from the form but the second picture.  Now this needs to go through MS Outlook.  Now I have down loaded PHPMailer and I am new to php and tried it did not get any errors with but did not get any information with it either.

To be honest with you your code is a bit of a mess and the mail() function within php is not meant for attachments.

If you want to send email including attachments then use PEAR::Mail Mime. So much easier!

 

Package found at:

http://pear.php.net/package/Mail_Mime

 

Here is a copy of the form the I am attaching the php code to:

<form action="email.php" method="post" enctype="multipart/form-data">

<p align="center" class="style8"><span class="style16"><strong><span class="style19">ONLINE APPICATION<br /></span>                   

<span class="style18">Free to Submit an Application!</span></strong> <strong> <br /><a href="form.pdf" target="_blank">click here</a> to print out form to mail</strong> <br /></span> </p>

<p>Name:

  <input name="Name" type="text" id="Name" size="45" />

  </p>

<p>Address:

  <textarea name="Address" cols="45" id="Address"></textarea>

  </p>

<p>City:

  <input name="City" type="text" id="City" size="25" />

  State:

  <input name="State" type="text" id="State" size="4" />

  Zip:

  <input name="Zip" type="text" id="Zip" size="10" />

  Home Phone:

  <input name="Phone" type="text" id="Home Phone" size="20" />

  Cell Phone:

  <input name="Cell" type="text" id="Cell Phone" size="20" />

  </p>

<p>Email:

  <input name="Email" type="text" id="Email" size="35" />

  </p>

<p>Your Dog's Info

  Name of Your Dog:

  <input name="DogsName" type="text" id="Name of Your Dog" size="45" />

  </p>

<p>Age of Dog:

  <input name="DogsAge" type="text" id="Age of Dog" size="4" />

  Breed:

  <input name="Breed" type="text" id="Breed" size="25" />

  </p>

<p>Weight:

  <input name="DogsWeight" type="text" id="Weight of Dog2" size="4" />

  lbs  </p>

<p>Sex of Dog:

  Male

  <input type="checkbox" name="DogsSex" id="Male Dog" value="Male" />

  Female

  <input type="checkbox" name="DogsSex" id="Female Dog" value="Female" />

</p>

<p>Spay/Neutered:

  <input type="checkbox" name="SpayNeutered" id="Spay/Neutered Yes" value="Yes" />

  Yes

  <input type="checkbox" name="SpayNeutered" id="Spay/Neutered No" value="No" />

  No  </p>

<p>Current Medications:

 

    <textarea name="Medications" cols="45" id="Medications"></textarea>

  </p>

  <p>Your Dog's Diet:   

    <textarea name="DogsDiet" cols="45" id="Your Dog's Diet"></textarea>

  </p>

  <p>Exercise:

    <textarea name="Exercise" cols="45" id="Exercise"></textarea>

  </p>

  <p>Your Dog's Story:

    <textarea name="DogsStory" cols="45" id="Your Dog's Story">200 words max.</textarea>

  </p>

  <p>Check all that Apply:

    <input type="checkbox" name="Diabetes" id="Diabetes" value="X" />

    Diabetes

    <input type="checkbox" name="KidneyLiver" id="Kidney/Liver Disease" value="X" />

    Kidney/Liver Disease<br />

      <input type="checkbox" name="FoodAllergies" id="Food Allergies" value="X" />

    Food Allergies

    <input type="checkbox" name="HeartDisease" id="Heart Disease" value="X" />

    Heart Disease<br />

      <input type="checkbox" name="Other" id="Other" value="X" />

    Other</p>

</div>

Pictures of your Dog1 side view & 1 overhead view

  (jpgs only; 1MB totoal) 

<p>Picture 1

  <input type="file" name="Picture1" id="Picture1" />

  <br />

  Picture 2

  <input type="file" name="Picture2" id="Picture2" />

  <br />

 

</p>

<td valign="middle"><div align="left"><span class="style8"></span></div>

  </label></td></tr></table><label><div align="center">

<input type="submit" name="Submit" id="Submit" value="Send" />

<input type="reset" name="Reset" id="Reset" value="Reset" /></form>

 

** I need a copy of the form sent in the email with the information with the pictures.

 

 

Again I new to this so if anyone has a detail tut on how to do this I would be great full.  I have downloaded PHPMailer yesterday but then I still learning so if any has a tut on how to do this I would be greatful.

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.