Skip to main content
Inspiring
December 20, 2018
Question

Php Email Submission Form Question

  • December 20, 2018
  • 0 replies
  • 487 views

Does anyone know how the following php script could be altered to allow a file upload via email. All of the fields except the Upload File field come through in an email.

https://www.logomatcentral.com/Test-03.html

the PHP script is:

<?php

if(isset($_POST)) {

    // EDIT THE 2 LINES BELOW AS REQUIRED

    $email_to = "admin@doormatsandmore.com";

    $email_from = "admin@doormatsandmore.com";

    $email_subject = "Test HTML from Using PHP";

  if(!isset($name) || empty($name)) {

    array_push($errors, 'The Name you entered does not appear to be valid.');

  }

 

  if(!isset($comments) || empty($comments) || strlen($comments) < 2) {

    array_push($errors, 'The Comments you entered do not appear to be valid.');

  }

    $name = $_POST['name']; // required

    $orientation = $_POST['orientation']; // required

    $size = $_POST['size']; // required

    $select = $_POST['select']; // required

    $files = $_POST['files']; // required

    $comments = $_POST['comments']; // required

    

    $response = array('status' => false, 'message' => array());

    if(!empty($response['message'])) {

        foreach($errors as $err) {

            echo $err, '<br />';

        }

        die();

    } else {

        $email_body = "Form details below.\n\n";

        $email_body .= "Name: ".$name."\n";

        $email_body .= "Orientation: ".$orientation."\n";

        $email_body .= "Size: ".$size."\n";

        $email_body .= "Select: ".$select."\n";

        $email_body .= "Files: ".$files."\n";

        $email_body .= "Comments: ".$comments."\n";

        // create email headers

        $headers = 'From: '.$email_from."\r\n".

        'Reply-To: '.$email_from."\r\n" .

        'X-Mailer: PHP/' . phpversion();

        if(mail($email_to, $email_subject, $email_body, $headers)) {

             echo 'Thank you for submitting form. We will be in touch with you very soon.';

             die();

        }

    }

}

?>

The HTML structure is:

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>Untitled Document</title>

<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">

</head>

<body>

  <div class="container">

    <div class="col-sm-6" style="padding-top:50px;">

        <div class="well">

            <h2>How To Send Feedback Form Through PHP Email</h2>

        </div>

        <div class="col-md-12">

       

          <div class="form-area">

          

            <form role="form" id="frm_feedback" name="frm_feedback" action="Test-03.php" method="post" enctype="multipart/form-data">

           

              <div class="alert alert-success hide"></div>

             

              <br style="clear:both">

             

              <h3 style="margin-bottom: 25px; text-align: center;">Feedback Form</h3>

              <div class="alert alert-danger hide"></div>

             

              <div class="form-group">

                <input type="text" class="form-control" id="name" name="name" placeholder="Name"/>

              </div>

             

              <div class="form-group">

               <select class="form-control" id="orientation" name="orientation" placeholder="choose">

                 <option value="portrait">Portrait</option>

                 <option value="landscape">landscape</option>

               </select>

              </div>

             

              <div class="form-group">

               <select class="form-control" id="size" name="size" placeholder="choose">

                 <option value="02x03">02' x 03'</option>

                 <option value="03x04">03' x 04'</option>

                 <option value="04x06">04' x 06'</option>

               </select>

              </div>

             

              <div class="form-group">

               <select class="form-control" id="select" name="select" placeholder="choose">

                 <option value="red">Red</option>

                 <option value="green">Green</option>

                 <option value="blue">Blue</option>

                 <option value="yellow">Yellow</option>

                 <option value="purple">Purple</option>

               </select>

              </div>

             

              <div class="form-group">

                 <input class="form-control" type="file" id="files" name="files">

              </div>

             

              <div class="form-group">

                <textarea class="form-control" type="textarea" id="comments" name="comments" placeholder="comments" maxlength="140" rows="7"></textarea>              

              </div>

             

              <button type="submit" id="submit" name="submit" class="btn btn-primary pull-right">Submit Form</button>

            </form>

          </div>

        </div>

    </div>

  </div>

</div>

</body>

</html>

This topic has been closed for replies.