Jump to content

Form to mail: sending files!? my script needs help!


ponies3387

Recommended Posts

I created this form in dreamweaver and theres no problem with it that I can tell, but incase u need it for helping me, here it is: (keep scrolling to see the script that needs help!)

    <form action="process.php" method="post" enctype="multipart/form-data" name="Form" class="style1" id="Form">

         

        <div align="left">

                <blockquote>

                  <p><span class="style11">E-mail:          </span>

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

                    <br />

                    <span class="style6">I have text here</span><br />

                    <br />

                    <br />

                    <span class="style11"> Image:</span>

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

                    <br />

                    <br />

                    <br />

                    <span class="style12">more text here</span><br />

                    <br />

                    <input type="checkbox" name="1" id="1" />

                    standard retouch  <br />

                    <span class="style6">blah blah checkbox</span><br />

                    <input type="checkbox" name="2" id="2" />

                    anothercheckbox description<br />

                    <input type="checkbox" name="3" id="3" />

                    last checkbox<br />

                    <br />

                    More options will be added in the near future!<br />

                    <br />

                    <br />

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

                    <span class="style6">final text</span><br />

                    <br />

                  </p>

                </blockquote>

              </div>

        </form>

 

Its asks for the users email, lets them browse to select a file to upload, and then theres some checkboxes, then of course, a submit button.

 

Heres the script I wrote to send this form to my e-mail: (note:I have no previous experience writing php this is my 1st try which I have been improving throughout the week)

 

<?php

  $email = $_REQUEST['Email'] ;

  $file = $_REQUEST['Image'] ;

  $check1 = $_REQUEST['1'] ;

  $check2 = $_REQUEST['2'] ;

  $check3 = $_REQUEST['3'] ;

  $submit = $_REQUEST['Submit'] ;

 

$message = "

Email address = $email

Checkbox1 = $check1

Checkbox2 = $check2

Checkbox3 = $check3";

 

  mail( "info@changed.com", "New Sent Photo",

    $message, "From: $email" );

  header( "Location: http://www.changed.com/SendSuccess.html" );

?>

 

I receive the email just fine along with the checkbox answers, my only issue is I want the file upload part of the form to be sent to me as an attachment, but thats where theres something wrong because I dont get sent anything about the file in the email. I have spent all week researching and im really frustrated about this. Im getting very easily confused by all these form to mail tutorials because few of them even mention attachments, and the ones that do I cant get to work because there so technical and im so new to this stuff. If someone can please tell me exactly what to insert in my script and where it belongs in my script you could rid me of this headache. 

 

Im using a linux server if that even matters, and I just figured php was the best way to go about this. I tried dreamweaver extension programs, but they dont do the job. I need something easy to follow.

Link to comment
Share on other sites

Ok, all looks good so far! What you first need to do, is make sure that the users image gets uploaded to your server. From there on you can send it as an attachment.

 

First modification to your code is that you need to copy the image to your server. This should replace your  $file = $_REQUEST['Image'] ;

 

copy ($_FILES['Image']['tmp_name'], "files/".$_FILES['Image']['name']) or die ("Could not copy");

 

Make sure you have a folder called files in the same directory your contact form is in.

 

From there, we need to include this uploaded image in your email. I will include this in my next reply unless someone answers sooner.

 

Check this by the way - the code I gave you is very simple and doesnt check if the file uploaded is actually an image. You should add this checker since its a security risk not to: http://www.phpfreaks.com/tutorials/36/0.php

 

 

Link to comment
Share on other sites

Thank you! If I understood that link you sent me, this is what I have now:

 

<?php

  $email = $_REQUEST['Email'] ;

  <?

if(isset( $Submit ))

{

 

if ($_FILES['Image']['type'] == "image/jpeg"){

       

  ($_FILES['Image']['tmp_name'], "files/".$_FILES['Image']['name']) or die ("Could not copy");

  echo "";

        echo "Name: ".$_FILES['Image']['name']."";

        echo "Size: ".$_FILES['Image']['size']."";

        echo "Type: ".$_FILES['Image']['type']."";

        echo "Copy Done....";

        }

else {

            echo "<br><br>";

            echo "Could Not Copy, Wrong Filetype (".$_FILES['Image']['name'].")<br>";

        }

}

  $check1 = $_REQUEST['1'] ;

  $check2 = $_REQUEST['2'] ;

  $check3 = $_REQUEST['3'] ;

  $submit = $_REQUEST['Submit'] ;

 

$message = "

Email address = $email

Checkbox1 = $check1

Checkbox2 = $check2

Checkbox3 = $check3";

 

  mail( "info@changed.com", "New Sent Photo",

    $message, "From: $email" );

  header( "Location: http://www.changed.com/SendSuccess.html" );

?>

 

So what now?  ??? Im assuming theres another step im missing...

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.