Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Aug 2018
    Posts
    1
    Member #
    59828

    PHP form driving me insane

    HI everyone, ive spent all day trying to get my form working. I have created a very simple form but I cannot get the 'file upload' to upload any files, The form submits the other info to me to my email address but no uploads come my way ... please help! I dont need the images sent to me stored anywhere, a simple email attachment is what I need.

    My form can be found at https://www.famestreet.com/contact/contacttest.htm and the php page is at https://www.famestreet.com/forms/contact.php

    Here is the PHP code:

    <?php
    if(isset($_POST['email'])) {
    // CHANGE THE TWO LINES BELOW
    $email_to = "support@famestreet.com";
    $email_subject = "conttest";

    function died($error) {
    // your error code can go here
    echo "We are very sorry, but there were error(s) found with the form you submitted. ";
    echo "These errors appear below.<br /><br />";
    echo $error."<br /><br />";
    echo "Please go back and fix these errors.<br /><br />";
    die();
    }

    // validation expected data exists
    if(!isset($_POST['first_name']) ||
    !isset($_POST['email']) ||
    !isset($_POST['roles']) ||
    !isset($_POST['anything'])) {
    died('We are sorry, but there appears to be a problem with the form you submitted.');
    }

    $ref = $_POST['ref']; // required
    $first_name = $_POST['first_name']; // required
    $username = $_POST['username']; // required
    $profile = $_POST['profile']; // required
    $email_from = $_POST['email']; // required
    $roles = $_POST['roles']; // not required
    $anything = $_POST['anything']; // required
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

    if(strlen($error_message) > 0) {
    died($error_message);
    }
    $email_message = "Form details below.\n\n";

    function clean_string($string) {
    $bad = array("content-type","bcc:","to:","cc:","href");
    return str_replace($bad,"",$string);
    }

    $email_message .= "Ref: ".clean_string($ref)."\n";
    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Username: ".clean_string($username)."\n";
    $email_message .= "Profile: ".clean_string($profile)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "roles: ".clean_string($roles)."\n";
    $email_message .= "anything: ".clean_string($anything)."\n";

    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);
    ?>
    <?php
    }
    die();
    ?>

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,622
    Member #
    5580
    Liked
    711 times
    When you upload a file in a form, you cannot just read it in and email it.

    The upload function in a form is designed for the file to be saved on your website (in a directory).

    In order to email a file, it has to be attached. So you upload the file to a directory, then build the email with that attaches that file to the email. At that point you can delete it from your directory, or keep it there. The recipient will see the file attached in their email.

    So first save the file to a directory, then process the email with that file as an attachment.

    Google: PHP email file attachment


  4. #3
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,622
    Member #
    5580
    Liked
    711 times
    I suggest you do the email part first, and simply attach a test file you have on your website. Get that working and then you can work on the part where the form uploads a selected file to your website. Basically, you are doing those two things separately.



Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 11:27 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com