www.webdeveloper.com
Results 1 to 3 of 3

Thread: email form problem

  1. #1
    Join Date
    Nov 2002
    Posts
    91

    email form problem

    Can any body see what is wrong with my code, I just can't get it to work.
    Thanks

    PHP Code:
    <?php
    header 
    ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");                    // Date in the past
    header ("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");   // Always modified
    header ("Cache-Control: no-cache, must-revalidate");                // HTTP/1.1
    header ("Pragma: no-cache");                                                        // HTTP/1.0

    //input


    //writes out selected if value matches variable value
    function write_sel($val$match) {
        if (
    $val==$match) {
            echo(
    "checked");
        }
    }

    //writes out "options" for all the referral methods
    function write_referrals () {
        
    $Referral = array("Search Engine""Word of Mouth""Advertisment""Other");
        foreach(
    $Referral as $index => $val) {
            if (
    $val == $GLOBALS["referrals"]) {
                echo(
    "<option value=\"$val\" selected>$val</option>\r\n");
            } else {
                echo(
    "<option value=\"$val\">$val</option>\r\n");
            }
        }
    }


    $val_msg "";
    //if we are receiving a posted back form
    if ($postback == "Y") {
        
    //ensures that all fields are have been filled in correctly
        
    if ($FirstName == "") {
            
    $val_msg "Please enter your <strong>first name</strong> and click submit.";
        } elseif (
    $LastName == "") {
            
    $val_msg "Please enter your <strong>last name</strong> and click submit.";
        }  elseif (
    $Email == "") {
            
    $val_msg "Please enter your <strong>e-mail address</strong> and click submit.";
        } elseif (!
    eregi("^[_\-\.0-9a-z]+@([0-9a-z][_0-9a-z\.]+)\.([a-z]{2,4}$)"$email)) {
            
    $val_msg "The e-mail address you entered is not valid. Please enter a valid <strong>e-mail address</strong> and click submit.";
        }   
        
        if (
    $val_msg != "") {
            
    $val_msg "<font color='#FF0000' face='Arial, Helvetica, sans-serif' size='3'>Required field(s) were not properly filled out. " $val_msg "</font>";
        } else {
            
    //compose message
            
    $msg "The following is a request for additional information from your website.\r\n\r\n";
            
    $msg .= "From: $FirstName $LastName\r\n";
            
    $msg .= "E-mail: $Email\r\nPhone Number: $Phone\r\n\r\n";
            
    $msg .= "Address:\r\n$Address\r\n$Address2\r\n$City\r\n$State$Country\r\n$Zip\r\n\r\n";
            
    $msg .= "Comments:$Comments\r\n\r\n";
            
    $msg .= "How did you hear about us:$Referral\r\n";
            
            
            
    //send e-mail and redirect
            //first e-mail is where it will be sent to, next is title, then the message, the other headers
            
    if (!mail("xxx@xxxx.com""Additional Information"stripslashes($msg), "From: xxxx\r\nReply-to: $email\r\n")) {
                
    $val_msg "The system was unable to send your request. Please contact them directly via <a href='xxx@xxx.com'>e-mail</a> or by telephone / regular mail.";
            } else {
                
    //redirect the page to...may require modification
                
    header("Location: http://xxxxx/html/thankyou.htm");
            }
        }
    }
    ?>



    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
     <META http-equiv=Content-Type content="text/html; charset=windows-1252">
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <table width="412" height="180" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="145" height="12" class="contacttable"><p class="contacttitle">* First Name:</p></td>
        <td width="267" height="12" class="contacttable">
          <input name="FirstName" type="text" id="FirstName" size="20" maxlength="50" value="<?php echo($FirstName); ?>" /></td>
      </tr>
      <tr>
        <td height="12" class="contacttable"><p class="contacttitle">* Last Name:</p></td>
        <td height="12" class="contacttable">
          <input name="LastName" type="text" id="LastName" size="20" maxlength="50" value="<?php echo($LastName); ?>" />
        </td>
      </tr>
      <tr>
        <td height="12" class="contacttable"><p class="contacttitle">Address:</p></td>
        <td height="12" class="contacttable">
          <input name="Address" type="text" id="Address" size="20" maxlength="50" value="<?php echo($Address); ?>" />
        </td>
      </tr>
      <tr>
        <td height="12" class="contacttable"><p class="contacttitle">Address2:</p></td>
        <td height="12" class="contacttable">
          <input name="Address2" type="text" id="Address2" size="20" maxlength="50" value="<?php echo($Address2); ?>" />
        </td>
      </tr>
      <tr>
        <td height="12" class="contacttable"><p class="contacttitle">City:</p></td>
        <td height="12" class="contacttable">
          <input name="City" type="text" id="City" size="20" maxlength="50" value="<?php echo($City); ?>"/>
        </td>
      </tr>
      <tr>
        <td height="12" class="contacttable"><p class="contacttitle">State/Province:</p></td>
        <td height="12" class="contacttable">
          <input name="State" type="text" id="State" size="10" maxlength="30" value="<?php echo($State); ?>" />
        </td>
      </tr>
      <tr>
        <td height="12" class="contacttable"><p class="contacttitle">Zip/Postal Code :</p></td>
        <td height="12" class="contacttable">
          <input name="Zip" type="text" id="Zip" size="10" maxlength="30" value="<?php echo($Zip); ?>"/>
        </td>
      </tr>
      <tr>
        <td height="12" class="contacttable"><p class="contacttitle">Country:</p></td>
        <td height="12" class="contacttable">
          <input name="Country" type="text" id="Country" size="20" maxlength="50" value="<?php echo($Country); ?>"/>
        </td>
      </tr>
      <tr>
        <td height="12" class="contacttable"><p class="contacttitle">Daytime Phone :</p></td>
        <td height="12" class="contacttable">
          <input name="Phone" type="text" id="Phone" size="15" maxlength="20" value="<?php echo($Phone); ?>"/>
        </td>
      </tr>
      <tr>
        <td height="12" class="contacttable"><p class="contacttitle">* Email:</p></td>
        <td height="12" class="contacttable">
          <input name="Email" type="text" id="Email" size="20" maxlength="50" value="<?php echo($Email); ?>"/>
        </td>
      </tr>
      <tr>
        <td height="12" colspan="2" class="contacttable"><p class="thirdtitle"><span class="contacttitle">How did you hear about us?</span> &nbsp;&nbsp;&nbsp;
                <select name="Referral" size="1">
                  <option value="" selected="selected">&lt;Select&gt;</option>
                  <?php write_referrals(); ?>
                </select>
        </p></td>
      </tr>
      <tr>
        <td height="12" class="contacttable"><p class="contacttitle">Comments/Questions/Information request:</p></td>
        <td height="12" class="contacttable"><p>
            <textarea name="Comments" cols="25" rows="5" id="Comments"><?php echo($Comments); ?></textarea>
        </p></td>
      </tr>
      <tr>
        <td height="12" colspan="2"><p>
            <input type="submit" name="Submit" value="Submit" />
    &nbsp;&nbsp;&nbsp;
            <input type="reset" name="reset" value="Reset" />
        </p></td>
      </tr>
    </table>
    </body>
    </html>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,925
    Can you narrow down by what you mean when you say it does not work? Do you get any error messages? If not, you might want to make sure all PHP errors are displayed with this at the start of your script:
    PHP Code:
    <?php
    ini_set
    ('display_errors'1);
    error_reporting(E_ALL);
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Nov 2002
    Posts
    91
    Thanks very much, I'll try that.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles