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 7 of 7
  1. #1
    Member
    Join Date
    Jul 2005
    Posts
    77
    Member #
    10681
    Hey everyone,

    I've got a simple PHP mail form working on the intranet at work and I've been trying to customize it for our use. Basically it's going to be a form that teachers can fill in when there is a lock-down (drill or otherwise) to inform the necessary people that they are okay.

    It's going well but there's just a few things it's not doing:

    - I want the From: field of the resulting e-mail to display either the real address that it comes from or just 'Lockdown Report'... Currently it comes up with name@someobscuredomain.edu.au (where name is what the user has typed as their name)

    - I was also wondering if it was possible to tabulate the resulting e-mail or at least bold the answers to the questions, so the person who receives the e-mail isn't sifting through it all

    - If you leave a field blank and click 'Submit' it tells you to go back and fill in all fields, but it still sends the e-mail! Is there any way I can tell it not to send the e-mail in this case?

    The script is below (it consists of two files) - if anyone could help me out with any of these three things I'd be forever greatful!!!!

    Thanks!
    Neil

    sendeail.php
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>Sendemail Script</title>
    </head>
    <body>

    <!-- $myemail is the address that lockdown reports will go to --> 

    <?php

    $myemail 
    "neil@greenvaleps.vic.edu.au"
    $ccx ""

    if(empty(
    $name) || empty($grades) || empty($missing) || empty($other) || empty($acc)) {
    echo 
    "<h2>Please click the Back button and fill in all fields</h2>\n";
    }


    $todayis date("l, F j, Y, g:i a") ;

    $subject $name

    $missing stripcslashes($missing); 

    $message $todayis [EST] \n
    Staff Member Submitting Form: 
    $name \n
    Grade(s): 
    $grades \n
    All Students Accounted For?  
    $acc \n
    Missing Students: 
    $missing \n 
    Names of Others In Classroom (eg. Support Staff, Visitors, Parents, Tradesmen): 
    $other \n
    "
    ;

    $from "From: $name \r\n";



    if (
    $myemail != ""
    mail($myemail$subject$message$from);

    if (
    $ccx != ""
    mail($ccx$subject$message$from);

    ?>

    <p align="center">
    <strong>Thankyou <?php echo $name ?> 
    <br />
    <br />
    You sent the following results:</strong><br />
    <br />
    <strong>Grade(s):</strong> <?php echo $grades ?>
    <br />
    <br />
    <strong>All Students Accounted For?</strong> <?php echo $acc ?>
    <br />
    <br /> 
    <strong>Missing Students:</strong><br /> 
    <?php echo $missing ?> 
    <br />
    <br />
    <strong>Names of Others In Classroom (eg. Support Staff,<br />
    Visitors, Parents, Tradesmen):</strong> <?php echo $other ?><br />
    <br />
    <strong>Date &amp; Time Sent:</strong> <?php echo $todayis ?>

    <br /><br />
    <a href="http://10.77.181.13:81"> Home </a> 
    </p> 

    </body>
    </html>
    ...and contact.php
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Lockdown Form</title>
    </head>
    <body>

    <form method="post" action="sendeail.php">

    <!-- DO NOT change ANY of the php sections -->
    <?php
    $ipi 
    getenv("REMOTE_ADDR");
    $httprefi getenv ("HTTP_REFERER");
    $httpagenti getenv ("HTTP_USER_AGENT");
    ?>

    <input type="hidden" name="ip" value="<?php echo $ipi ?>" />
    <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
    <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />


    Your Name: <br />
    <input name="name" type="text" id="name" size="35" />
    <br />
    <br />
    Grade(s):<br />
    <input name="grades" type="text" id="grades" size="35" />
    <br /> <br />
    All Students Accounted For ? No
    <input name="acc" type="radio" value="No" />   
    Yes<input name="acc" type="radio" value="Yes" /> 
    <br />
    <br /> 

    Names of Missing Children:
    <br />
    <textarea name="missing" cols="40" rows="4" id="missing"></textarea>
    <br />
    <br />
    Names of Others In Classroom (eg. Support

    Staff,<br /> 
    Visitors, Parents, Tradesmen):<br />
    <textarea name="other" cols="40" rows="4" id="other"></textarea>
    <br />
    <br />
    <input type="submit" value="Send Mail" />
    <br />

    <!-- Free Code at: http://www.ibdhost.com/contact/ --> 

    </form>

    </body>
    </html>

  2.  

  3. #2
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    137 times
    Basic way to stop it from sending incomplete email:

    if(empty($name) || empty($grades) || empty($missing) || empty($other) || empty($acc)) {
    echo "<h2>Please click the Back button and fill in all fields</h2>\n";
    }

    else {

    $todayis = date("l, F j, Y, g:i a") ;

    $subject = $name;

    $missing = stripcslashes($missing);

    $message = " $todayis [EST] \n
    Staff Member Submitting Form: $name \n
    Grade(s): $grades \n
    All Students Accounted For? $acc \n
    Missing Students: $missing \n
    Names of Others In Classroom (eg. Support Staff, Visitors, Parents, Tradesmen): $other \n
    ";

    $from = "From: $name \r\n";

    if ($myemail != "")
    mail($myemail, $subject, $message, $from);

    if ($ccx != "")
    mail($ccx, $subject, $message, $from);

    }

    Didn't read all of the code (about to go to sleep), but I think if it finds incomplete info it doesn't bring them back to entry form, and pre-fill out already done info?
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  4. #3
    Member
    Join Date
    Jul 2005
    Posts
    77
    Member #
    10681
    That worked a treat! Thanks heaps!!!

    My main problem now is making the resulting e-mail more easily readable... The person who receives them will be getting about 30-40 and it may be in an emergency situation so they need to be able to quickly compile the answers to the questions.

    Can anyone help me put it into a table?

  5. #4
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Change
    PHP Code:
    $message $todayis [EST] \n 
    Staff Member Submitting Form: 
    $name \n 
    Grade(s): 
    $grades \n 
    All Students Accounted For? 
    $acc \n 
    Missing Students: 
    $missing \n 
    Names of Others In Classroom (eg. Support Staff, Visitors, Parents, Tradesmen): 
    $other \n 
    "

    To
    PHP Code:
    $message "<table width=\"50%\" style=\"border: 1px solid black;\">\n<tr>\n<td> $todayis [EST] \n 
    Staff Member Submitting Form: 
    $name \n 
    Grade(s): 
    $grades \n 
    All Students Accounted For? 
    $acc \n 
    Missing Students: 
    $missing \n 
    Names of Others In Classroom (eg. Support Staff, Visitors, Parents, Tradesmen): 
    $other \n</td>\n</tr>\n</table>"
    You may wish to tweak the tables css style.

  6. #5
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    To enable html entities in your mail, you have to add some headers to your mail() function.
    Otherwise, all tags like <b>, <table> etc, will just show up in clear text at the recieving end.

    PHP Code:
    $headers  "MIME-Version: 1.0\r\n"
    $headers .= "Content-type: text/html; "
    $headers .= "charset=iso-8859-1\r\n"
    $headers .= "From: $from\r\n";

    mail($myemail$subject$message$headers) or die("Failure"); 
    S. Rosland

  7. #6
    Member
    Join Date
    Jul 2005
    Posts
    77
    Member #
    10681
    You guys rock!!! Thankyou so much! I'll give it a go tomorrow at work...
    Cheers
    Neil

  8. #7
    Member
    Join Date
    Jul 2005
    Posts
    77
    Member #
    10681
    I forgot to come back and let you know it worked... Thankyou!


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 10:53 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com