Solved

html form, email me

Posted on 2010-11-30
21
172 Views
Last Modified: 2013-12-25
I have an HTML contact form with tons of fields. Before it was on a server that did CGI and emailed it to me. I dont have access to that script.

I need a new CGI or PHP that will email me the contents. any ideas? thanks
0
Comment
Question by:shankshank
21 Comments
 
LVL 2

Expert Comment

by:Jogai
ID: 34238660
Here is a php script you can use: http://jemturner.co.uk/scripts/free-php-mail-form/
0
 
LVL 5

Author Comment

by:shankshank
ID: 34238679
I dont like this one. It wants me to redo the entire form on the PHP script.
I want to be able to keep my HTML page and just post the form data into the PHP script
0
 
LVL 19

Expert Comment

by:Bardobrave
ID: 34238722
You can send a whole HTML result as a mail with the mail method of PHP.

Take a look at the specification of the method: http://es2.php.net/manual/en/function.mail.php

What you need to do is to build the HTML of the mail from within the form response and use mail method to send it to you.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 109

Expert Comment

by:Ray Paseur
ID: 34238772
I want to be able to keep my HTML page and just post the form data into the PHP script.

Give us a hand here... Show us the HTML page!

Here is what the PHP script will be doing (see code snippet for the teaching example of the form-to-email script).
<?php // RAY_form_to_email.php
error_reporting(E_ALL);

// SEND MAIL FROM A FORM

// A FUNCTION TO CLEAN UP THE DATA - AVOID BECOMING AN OPEN-RELAY FOR SPAM
function clean_string($str)
{
    $str = stripslashes($str);
    $str = trim(preg_replace("/ +/", " ", $str));
    $str = preg_replace('/^ a-zA-Z0-9&+:?_\.\-/', '', $str);
    return $str;
}

// REQUIRED VALUES ARE PREPOPULATED - CHANGE THESE FOR YOUR WORK
$from  = "NoReply@Your.org";
$subj  = "Contact Form";

// THIS IS AN ARRAY OF RECIPIENTS
$to[]  = "You@Your.org";
$to[]  = "Her@Your.org";
$to[]  = "Him@Your.org";

// IF THE DATA HAS BEEN POSTED
if (!empty($_POST['email']))
{
    // CLEAN UP THE POTENTIALLY BAD AND DANGEROUS DATA
    $email      = clean_string($_POST["email"]);
    $name       = clean_string($_POST["name"]);
    $telephone  = clean_string($_POST["telephone"]);

    // CONSTRUCT THE MESSAGE
    $content    = '';
    $content   .= "You have a New Query From $name \n\n";
    $content   .= "Tel No: $telephone\n";
    $content   .= "Email: $email\n";

    // SEND MAIL TO EACH RECIPIENT
    foreach ($to as $recipient)
    {
        if (!mail( $recipient, $subj, $content, "From: $from\r\n"))
        {
            echo "MAIL FAILED FOR $recipient";
        }
        else
        {
            echo "MAIL WORKED FOR $recipient";
        }
    }
} // END OF PHP - PUT UP THE FORM
?>
<form method="post">
<br/>Email: <input name="email" />
<br/>Phone: <input name="telephone" />
<br/>Name:  <input name="name" />
<br/><input type="submit" />
</form>

Open in new window

0
 
LVL 5

Author Comment

by:shankshank
ID: 34239048
hahahaha

The HTML is simple. It's just a basic HTML form. I want it to dump that to my email.
0
 
LVL 5

Author Comment

by:shankshank
ID: 34239062
The goal here is i want to take that form and email it, and beable to modify the HTML form anytime without having to modify additional code ie. php script and it's variables...
so maybe PHP isnt the way to go, maybe CGI would do it?

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 34239144
PHP will work fine for what you want to do.  But please work with us here.  Please post the HTML form in the code snippet.  Life is so much easier for everyone when we can see what you're talking about.  Then we can give you concrete solutions instead of generalizations and half-answers.  Thank you.
0
 
LVL 5

Author Comment

by:shankshank
ID: 34239165
<form method="post" action="../Scripts/email.php">
      <table border="0" cellpadding="0" cellspacing="1" class="textsmmed">
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Name</strong> (required) </td>
          <td><input type="radio" name="NamePrefix" value="Mr." />
            Mr.&nbsp;&nbsp;&nbsp;
            <input type="radio" name="NamePrefix" value="Mrs." />
            Mrs.&nbsp;&nbsp;&nbsp;
            <input type="radio" name="NamePrefix" value="Ms." />
            Ms.<br />
            <input name="Name" type="text" id="name" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Company</strong> (required)</td>
          <td><input type="text" name="Company" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Title</strong></td>
          <td><input type="text" name="Title" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Address</strong></td>
          <td><input type="text" name="Address" size="30" />
              <br />
              <input type="text" name="Addressb" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>City</strong></td>
          <td><input type="text" name="City" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>State</strong></td>
          <td><input type="text" name="State" size="10" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Zip</strong></td>
          <td><input type="text" name="Zip" size="10" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Country</strong></td>
          <td><input type="text" name="Country" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Address 2</strong></td>
          <td><input type="text" name="Address2" size="30" />
              <br />
              <input type="text" name="Address2b" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>City</strong></td>
          <td><input type="text" name="City2" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>State</strong></td>
          <td><input type="text" name="State2" size="10" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Zip</strong></td>
          <td><input type="text" name="Zip2" size="10" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Country</strong></td>
          <td><input type="text" name="Country2" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Phone</strong></td>
          <td><input type="text" name="Phone" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Fax</strong></td>
          <td><input type="text" name="Fax" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>E-mail</strong> (required)</td>
          <td><input type="text" name="Email" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
       
        <tr align="left" valign="top">
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Comments, Requests,<br />
            Suggestions</strong></td>
          <td><strong>
            <textarea name="Comments" cols="40" rows="4" wrap="virtual"></textarea>
          </strong></td>
        </tr>
        <tr align="left" valign="top">
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr align="left" valign="top">
                   
            <input type="hidden" name="subject" value="Contact Us request" />
            <input type="hidden" name="required" value="Name,Company,Email" />
            <input type="hidden" name="sort" value="order:NamePrefix,Name,Company,Title,Address,Addressb,City,State,Zip,Country,Address2,Address2b,City2,State2,Zip2,Country2,Phone,Fax,Email,InfoOn1,InfoOn2,InfoOn3,InfoOn4,Comments" /></td>
          <td><input type="submit" value="Send Message" /></td>
        </tr>
      </table>
      </form>

Open in new window

0
 
LVL 5

Author Comment

by:shankshank
ID: 34239180
here is the php code i found and was using. i changed my email for this post. also, the php script runs, as it takes me to the landing page, just no email.


 
<?php

error_reporting(E_ALL ^ E_NOTICE);

/*


SETUP INSTRUCTIONS

Step 1: Put the form on your webpage
Step 2: Enter your email address and (optional) continue link below
Step 3: Upload the files to your webspace

Step 1:

To put the form on your webpage, copy the code below as it is, and paste it into your webpage:

<form action="FormToEmail.php" method="post">
<table border="0" style="background:#ececec" cellspacing="5">
<tr align="left"><td>Name</td><td><input type="text" size="30" name="name"></td></tr>
<tr align="left"><td>Email address</td><td><input type="text" size="30" name="email"></td></tr>
<tr align="left"><td valign="top">Comments</td><td><textarea name="comments" rows="6" cols="30"></textarea></td></tr>
<tr align="left"><td>&nbsp;</td><td><input type="submit" value="Send"><font face="arial" size="1">&nbsp;&nbsp;<a href="http://FormToEmail.com">PHP Form</a> by FormToEmail.com</font></td></tr>
</table>
</form>

Step 2:

Enter your email address.

Enter the email address below to send the contents of the form to.  You can enter more than one email address separated by commas, like so: $my_email = "info@example.com"; or $my_email = "bob@example.com,sales@example.co.uk,jane@example.com";

*/

$my_email = "shank@test.com";

/*

Optional.  Enter a From: email address.  Only do this if you know you need to.  By default, the email you get from the script will show the visitor's email address as the From: address.  In most cases this is desirable.  On the majority of setups this won't be a problem but a minority of hosts insist that the From: address must be from a domain on the server.  For example, if you have the domain example.com hosted on your server, then the From: email address must be something@example.com (See your host for confirmation).  This means that your visitor's email address will not show as the From: address, and if you hit "Reply" to the email from the script, you will not be replying to your visitor.  You can get around this by hard-coding a From: address into the script using the configuration option below.  Enabling this option means that the visitor's email address goes into a Reply-To: header, which means you can hit "Reply" to respond to the visitor in the conventional way.  (You can also use this option if your form does not collect an email address from the visitor, such as a survey, for example, and a From: address is required by your email server.)  The default value is: $from_email = "";  Enter the desired email address between the quotes, like this example: $from_email = "contact@example.com";  In these cases, it is not uncommon for the From: ($from_email) address to be the same as the To: ($my_email) address, which on the face of it appears somewhat goofy, but that's what some hosts require.

*/

$from_email = "website@test.com";

/*

Optional.  Enter the continue link to offer the user after the form is sent.  If you do not change this, your visitor will be given a continue link to your homepage.

If you do change it, remove the "/" symbol below and replace with the name of the page to link to, eg: "mypage.htm" or "http://www.elsewhere.com/page.htm"

*/

$continue = "/";

/*

Step 3:

Save this file (FormToEmail.php) and upload it together with your webpage containing the form to your webspace.  IMPORTANT - The file name is case sensitive!  You must save it exactly as it is named above!

THAT'S IT, FINISHED!

You do not need to make any changes below this line.

*/

$errors = array();

// Remove $_COOKIE elements from $_REQUEST.

if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}

// Validate email field.

if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
{

$_REQUEST['email'] = trim($_REQUEST['email']);

if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ") || stristr($_REQUEST['email'],"\\") || stristr($_REQUEST['email'],":")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}

}

// Check referrer is from same site.

if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}

// Check for a blank form.

function recursive_array_check_blank($element_value)
{

global $set;

if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
else
{

foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}

}

}

recursive_array_check_blank($_REQUEST);

if(!$set){$errors[] = "You cannot send a blank form";}

unset($set);

// Display any errors and exit if errors exist.

if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}

if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}

// Build message.

function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}

$message = build_message($_REQUEST);

$message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL."Thank you for using FormToEmail from http://FormToEmail.com";

$message = stripslashes($message);

$subject = "FormToEmail Comments";

$subject = stripslashes($subject);

if($from_email)
{

$headers = "From: " . $from_email;
$headers .= PHP_EOL;
$headers .= "Reply-To: " . $_REQUEST['email'];

}
else
{

$from_name = "";

if(isset($_REQUEST['name']) && !empty($_REQUEST['name'])){$from_name = stripslashes($_REQUEST['name']);}

$headers = "From: {$from_name} <{$_REQUEST['email']}>";

}

mail($my_email,$subject,$message,$headers);

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>
<title>Message Sent</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#ffffff" text="#000000">

<div>
<center>
<b>Thank you <?php if(isset($_REQUEST['name'])){print stripslashes($_REQUEST['name']);} ?></b>
<br>Your message has been sent
<p><a href="<?php print $continue; ?>">Click here to continue</a></p>
</center>
</div>

</body>
</html>

Open in new window

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 34239424
Thanks for posting that.  The generalized solution to this problem is to take all the contents of $_POST and roll it into the email body.  I'll look over the form and see what we can do with that.
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 34239528
This worked for me, minus the validation processing, etc.  Install it on your server and try it and see if you get an email.
<?php // RAY_temp_shankshank.php
error_reporting(E_ALL);

// SET YOUR EMAIL HERE:
$my_email = 'You@Your.org';

// IF THE FORM HAS BEEN POSTED
if (!empty($_POST))
{
    $buf = NULL;
    foreach ($_POST as $key => $value)
    {
        $buf .= PHP_EOL . $key . ' = ' . $value;
    }
    $buf .= PHP_EOL;

    // SEND THE MAIL
    mail ($my_email, "FORM FROM {$_SERVER["HTTP_HOST"]}", $buf);

    // REDIRECT (OR ADD A 'THANK YOU' PAGE HERE)
    header("Location: /");
    exit;
}

// END OF PHP - USE HTML TO PUT UP THE FORM
?>
<form method="post">
      <table border="0" cellpadding="0" cellspacing="1" class="textsmmed">
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Name</strong> (required) </td>
          <td><input type="radio" name="NamePrefix" value="Mr." />
            Mr.&nbsp;&nbsp;&nbsp;
            <input type="radio" name="NamePrefix" value="Mrs." />
            Mrs.&nbsp;&nbsp;&nbsp;
            <input type="radio" name="NamePrefix" value="Ms." />
            Ms.<br />
            <input name="Name" type="text" id="name" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Company</strong> (required)</td>
          <td><input type="text" name="Company" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Title</strong></td>
          <td><input type="text" name="Title" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Address</strong></td>
          <td><input type="text" name="Address" size="30" />
              <br />
              <input type="text" name="Addressb" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>City</strong></td>
          <td><input type="text" name="City" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>State</strong></td>
          <td><input type="text" name="State" size="10" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Zip</strong></td>
          <td><input type="text" name="Zip" size="10" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Country</strong></td>
          <td><input type="text" name="Country" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Address 2</strong></td>
          <td><input type="text" name="Address2" size="30" />
              <br />
              <input type="text" name="Address2b" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>City</strong></td>
          <td><input type="text" name="City2" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>State</strong></td>
          <td><input type="text" name="State2" size="10" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Zip</strong></td>
          <td><input type="text" name="Zip2" size="10" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Country</strong></td>
          <td><input type="text" name="Country2" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Phone</strong></td>
          <td><input type="text" name="Phone" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Fax</strong></td>
          <td><input type="text" name="Fax" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>E-mail</strong> (required)</td>
          <td><input type="text" name="Email" size="30" />          </td>
        </tr>
        <tr align="left" valign="top">
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>

        <tr align="left" valign="top">
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr align="left" valign="top">
          <td bgcolor="#DEE1E4"><strong>Comments, Requests,<br />
            Suggestions</strong></td>
          <td><strong>
            <textarea name="Comments" cols="40" rows="4" wrap="virtual"></textarea>
          </strong></td>
        </tr>
        <tr align="left" valign="top">
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr align="left" valign="top">

            <input type="hidden" name="subject" value="Contact Us request" />
            <input type="hidden" name="required" value="Name,Company,Email" />
            <input type="hidden" name="sort" value="order:NamePrefix,Name,Company,Title,Address,Addressb,City,State,Zip,Country,Address2,Address2b,City2,State2,Zip2,Country2,Phone,Fax,Email,InfoOn1,InfoOn2,InfoOn3,InfoOn4,Comments" /></td>
          <td><input type="submit" value="Send Message" /></td>
        </tr>
      </table>
      </form>

Open in new window

0
 
LVL 5

Author Comment

by:shankshank
ID: 34239541
can i still have 2 separate files...? as that is how i have this whole site setup. php on one, html on main html site
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 34239606
Wow, now that I read it over, your old form-to-email script is a little scary.  In particular, like 80 which seems to try to do email validation, should be replaced with something a little more 21st century, like this.

Good programming also means readable programming.  It would probably help you understand the code better if you line up the control structures.

And you might want to add some data visualization.  This function is your friend.  Not only will it tell you when you've reached a certain point in the code, but it will tell you what is in your variables.  Very useful!
http://php.net/manual/en/function.var-dump.php
<?php // RAY_email_validation.php
error_reporting(E_ALL);



// A FUNCTION TO TEST FOR A VALID EMAIL ADDRESS, RETURN TRUE OR FALSE
function check_valid_email($email)
{
    // IF PHP 5.2 OR ABOVE, WE CAN USE THE FILTER
    // MAN PAGE: http://us3.php.net/manual/en/intro.filter.php
    if (strnatcmp(phpversion(),'5.2') >= 0)
    {
        if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) return FALSE;
    }
    // IF LOWER-LEVEL PHP, WE CAN CONSTRUCT A REGULAR EXPRESSION
    else
    {
        $regex
        = '/'                       // START REGEX DELIMITER
        . '^'                       // START STRING
        . '[A-Z0-9_-]'              // AN EMAIL - SOME CHARACTER(S)
        . '[A-Z0-9._-]*'            // AN EMAIL - SOME CHARACTER(S) PERMITS DOT
        . '@'                       // A SINGLE AT-SIGN
        . '([A-Z0-9][A-Z0-9-]*\.)+' // A DOMAIN NAME PERMITS DOT, ENDS DOT
        . '[A-Z\.]'                 // A TOP-LEVEL DOMAIN PERMITS DOT
        . '{2,6}'                   // TLD LENGTH >= 2 AND =< 6
        . '$'                       // ENDOF STRING
        . '/'                       // ENDOF REGEX DELIMITER
        . 'i'                       // CASE INSENSITIVE
        ;
        if (!preg_match($regex, $email)) return FALSE;
    }

    // FILTER_VAR OR PREG_MATCH DOES NOT TEST IF THE DOMAIN IS ROUTABLE
    $domain = explode('@', $email);

    // MAN PAGE: http://us3.php.net/manual/en/function.checkdnsrr.php
    if ( checkdnsrr($domain[1],"MX") || checkdnsrr($domain[1],"A") ) return TRUE;

    // EMAIL IS NOT ROUTABLE
    return FALSE;
}




// DEMONSTRATE THE FUNCTION IN ACTION
$e = '';
if (!empty($_GET["e"]))
{
    $e = $_GET["e"];
    if (check_valid_email($e))
    {
        echo "<br/>VALID: $e \n";
    } else
    {
        echo "<br/>BOGUS: $e \n";
    }
}
// END OF PHP - PUT UP THE FORM
?>
<form method="get">
TEST A STRING FOR A VALID EMAIL ADDRESS:
<input name="e" value="<?php echo $e; ?>" />
<input type="submit" />
</form>

Open in new window

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 34239623
Yes, you can have two separate files.  But I do not recommend that.  If you keep the PHP and HTML together you will save yourself a lot of headaches and confusion about "which version of the code am I using?"
0
 
LVL 5

Author Comment

by:shankshank
ID: 34240088
Hello.

Because we have multiple html contact pages, I would like to use the one external php file..
please let me know thanks
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 34240174
OK, then just post the data from the HTML forms to the PHP file.  Use the code snippet at ID:34239528 and delete everything below like 24.  Did you install that and test it yet?  What were the results?  Did you get the email?
0
 
LVL 5

Author Comment

by:shankshank
ID: 34240271
Hey! That worked. It was messy, but it did work.

So your code is MUCH smaller than the initial, so no checking etc .

Can we clean it up?

Thanks!
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 34240296
Clean it up?  Sure - be my guest!  I can show you the design patterns, but I cannot write your code for you.  For that you probably want to hire a professional developer.  But if you have other questions, please post them here at EE and I'll be glad (along with the other eexperts) to try to help.

Gotta go, good luck, ~Ray
0
 
LVL 5

Author Comment

by:shankshank
ID: 34240357
shucks.

hmm anyone know of a code that will do this, that is ready to go out of box? the other one i had i got off the web, must be something wrong with it. ray's works but too basic
0
 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 37158286
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question