SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP for a HTML Contact Form- please help me!

    Hi
    This is my 1st post. I am in desperate help in working out the php for the html form with attachment.

    I have send html forms before with php but i cant work out how to do it with the file attachement.

    Any help would be really appreciated.

    This is the HTML
    <form action="#" method="post" enctype="multipart/form-data" class="contact-form" id="contact-form">
    <fieldset class="group">
    <p>
    <input type="text" title="Your Name">
    </p>
    <p>
    <input type="text" title="Your E-mail">
    </p>
    </fieldset>

    <fieldset>
    <p>
    <textarea cols="30" rows="4" title="Skimage Title"></textarea>
    </p>
    </fieldset>
    <p>
    File to upload: <input type=file name=upfile></p>

    <button type="submit">Submit</button>

    </form>

    Thanks Again

  2. #2
    SitePoint Addict bronze trophy
    Join Date
    Sep 2005
    Posts
    318
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    You can grab the file form by doing $file = $_FILE['upfile']; . You will probably want to validate it too.

  3. #3
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do I just add that to the contact.php file

  4. #4
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im not sure what I am doing wrong but im getting everything but the attachment being sent through.


    This is my html:

    <form action="contact.php" method="post" enctype="multipart/form-data" name="contactform">
    <table width="450px">
    <tr>
    <td valign="top">
    <label for="name">Name *</label>
    </td>
    <td valign="top">
    <input type="text" name="name" maxlength="50" size="30">
    </td>
    </tr>
    <tr>
    <td valign="top">
    <label for="email">Email Address *</label>
    </td>
    <td valign="top">
    <input type="text" name="email" maxlength="80" size="30">
    </td>
    </tr>

    <tr>
    <td valign="top">
    <label for="enquiry">Skimage Title.*</label>
    </td>
    <td valign="top">
    <textarea name="enquiry" maxlength="1000" cols="25" rows="6"></textarea>
    </td>
    </tr><br>
    <tr>
    <td valign="top">
    <label for="upfile">Filename/label>
    <input type="file" name="file" id="file"><br>
    </td>
    </tr>
    <tr>
    <td colspan="2" style="text-align:center">
    <input type="submit" value="Submit">
    </td>

    This is my Php:

    <?php

    $EmailFrom = $_REQUEST['email'];
    $EmailTo = "hannah@muddypawswebdesign.co.uk"; //
    $Subject = "Contact form";
    $Name = Trim(stripslashes($_POST['name']));
    $Email = Trim(stripslashes($_POST['email']));
    $Message = Trim(stripslashes($_POST['skimage_title']));
    $file = $_FILE['file'];
    // validation
    $validationOK=true;
    if (!$validationOK) {
    echo "Error";
    exit;
    }

    // prepare email body text
    $Body = "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "Skimage_title: ";
    $Body .= "\n";
    $Body .= "\n";
    $Body .= $Skimage_title;
    $Body .= "\n";

    // send email
    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

    // redirect to success page
    if ($success){
    echo "Thankyou for your enquiry. We will be in touch very soon!";
    }
    else{
    echo "Error";
    }
    ?>

  5. #5
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    733
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    You don't have Content-Type: multipart/mixed headers in place. See this example.
    http://www.finalwebsites.com/forums/...achment-script


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •