1

I need to make a webform for users to input their information, choose a few selections from dropdown menus, and include an attachment. When submitting this form, it should generate and send an email to me.

All of the fields work (in that, they show up in the email I receive) the attachment (I have NO IDEA how to get attachments working). I have only had an intro to HTML course and never learned PHP, and it seems that no amount of googling is getting me the answer I want without completely rewriting all of my code. I'm hoping it's a quick fix, something I'm just overlooking.

Here is my HTML code:

<!DOCTYPE html>
 <html lang="en">
 <head>
    <meta charset="utf-8" />
    <title></title>
 </head>

<body>
    <div id="container">
        <header>
        </header>
    <div id="maincontent">
        <script>
            $(document).ready(function() {
                $(':text:first').focus();
            });
        </script>

        <div id="form_container">

        <form action="sendemail.php" method="post" enctype="multipart/form-data">
        <ul id="emailform">
            <li>
                <label for="ef_title">Title: </label>
                <span class="fieldbox"><input type="text" name="ef_title" required="required"></span>
            </li>
            <li>
                <label for="ef_users">Users Impacted: </label>
                <span class="fieldbox"><input type="text" name="ef_users" required="required"></span>
            </li>
            <li>
                <label for="ef_datetime">Date/Time: </label>
                <span class="fieldbox"><input type="datetime" name="ef_datetime" required="required"></span>
            </li>
            <li>
                <label for="ef_priority">Priority: </label>
                <p>

                    <select name="selectpri" required="required">
                      <option value="">Select...</option>
                      <option value="1">1</option>
                      <option value="2">2</option>
                      <option value="3">3</option>
                    </select>
                </p>
                <!-- <span class="fieldbox"><input type="datetime" name="ef_datetime" required="required"></span> -->
            </li>
            <li>
                <label for="ef_blocking">Blocking: </label>
                <p>

                    <select name="selectblock" required="required">
                      <option value="">Select...</option>
                      <option value="yes">Yes</option>
                      <option value="no">No</option>

                    </select>
                </p>
            </li>

            <li>
                <label for="ef_url">URL of Observed Behavior: </label>
                <span class="fieldbox"><input type="url" name="ef_url" required="required"></span>
            </li>

            <li>
                <label for="ef_desc">Description of Behavior: </label>
                <span class="msgbox"><textarea class="area" name="ef_desc" required="required"></textarea></span>
            </li>

            <li>
                <label for="ef_results">Expected Results: </label>
                <span class="msgbox"><textarea class="area" name="ef_results" required="required"></textarea></span>
            </li>

            <li>
                <label for="ef_repro">Repro Steps: </label>
                <span class="msgbox"><textarea class="area" name="ef_repro" required="required"></textarea></span>
            </li>
            <li>
                <label for='uploaded_file'>Select A File To Upload:</label>
                <input type="file" name="file" id="file">

            </li>


        </ul>
    <input id="sendbutton" type="submit" value="Send">
    <input id="clearbutton" type="reset" value="Clear">
    <br /><br />
</form>
    </div>




    </div>
    <footer>
    </footer>
    </div>
</body>
</html>

And here is my PHP code:

<?php


$field_title = $_POST['ef_title'];
$field_users = $_POST['ef_users'];
$field_datetime = $_POST['ef_datetime'];
$field_priority = $_POST['selectpri'];
$field_blocking = $_POST['selectblock'];
$field_url = $_POST['ef_url'];
$field_desc= $_POST['ef_desc'];
$field_results = $_POST['ef_results'];
$field_repro = $_POST['ef_repro'];
$field_attach = $_POST['file'];




$mail_to = 'katcole@uw.edu';
$subject = $field_title;

$body_message .= 'Title: '.$field_title."\n";
$body_message .= 'Users: '.$field_users."\n";
$body_message .= 'Date/Time: '.$field_datetime."\n";
$body_message .= 'Priority: '.$field_priority."\n";
$body_message .= 'Blocking: '.$field_blocking."\n";
$body_message .= 'URL of Observed Behavior: '.$field_url."\n";
$body_message .= 'Description of Behavior: '.$field_desc."\n";
$body_message .= 'Expected Results: '.$field_results."\n";
$body_message .= 'Repro Steps: '.$field_repro."\n";
$body_message .= 'Attachments: '.$field_attach."\n";




$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Thank you for the message. We will contact you shortly.');
        window.location = 'index.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email to v-jacoca@microsoft.com');
        window.location = 'index.html';
    </script>
<?php
}
?>

Thank you for your help in this matter! :)

3 Answers3

0

change this:

$field_priority = $_POST['ef_priority'];
$field_blocking = $_POST['ef_blocking'];

to this:

$field_priority = $_POST['selectpri'];
$field_blocking = $_POST['selectblock'];
Maximus2012
  • 1,799
  • 2
  • 12
  • 15
  • Thanks! This definitely fixed the dropdown menu problem! Can you offer any insight on the attachments issue? – kattermelon Jul 19 '13 at 22:00
  • the attachment one is not that straightforward. You need to look into the $_FILES global array as well as make changes to the mail() function. I am not sure if PHP mail() function supports attachments or how well it does so. You might want to look into PHPMailer() library. – Maximus2012 Jul 19 '13 at 22:02
  • do you want only the names of the attachments or the actual attached files too ? – Maximus2012 Jul 19 '13 at 22:03
  • check this answer for the attachment part: http://stackoverflow.com/questions/5814155/how-to-get-the-file-path-in-html-input-type-file-in-php see if that helps. – Maximus2012 Jul 19 '13 at 22:05
  • Definitely need the attached files too. – kattermelon Jul 19 '13 at 22:28
  • If I basically copied/pasted that solution into my code, do you think it would work? Also, where in the PHP code would it go? – kattermelon Jul 19 '13 at 22:31
  • look at this http://stackoverflow.com/questions/6275070/php-mail-attachment-problems and the other answer that I mentioned. – Maximus2012 Jul 19 '13 at 22:31
  • plain copy/paste won't work. You obviously need to make changes to your code to customize that solution to your code. First part would be make sure if you are getting atleast the name/type of the uploaded file and then the next step would be looking into the mail attachment part (2nd answer that I mentioned) – Maximus2012 Jul 19 '13 at 22:33
0

in your code you defined:

$field_priority = $_POST['ef_priority'];
$field_blocking = $_POST['ef_blocking'];

There is no form element name ef_priority and ef_blocking either change form element names or change your code to match the names

0

Change these:

<select name="selectpri" required="required">
<select name="selectblock" required="required">

to these:

<select name="ef_priority" required="required">
<select name="ef_blocking" required="required">

Also, you need to get the file from the HTML form please see this link below:

http://phpmaster.com/file-uploads-with-php/

verbanicm
  • 2,406
  • 1
  • 14
  • 9