Jump to content

e-mail validation


vietboy505

Recommended Posts

I need help on the e-mail form to work, can any one help me?

I want the form to check if everything is inputs correct such as an valid e-mail.

[code]
<?php

function determineEmail($Purpose)
{
        if($Purpose == "General") {
                $mailTo="Name1 <name1@mail.com>, Name2 <name2@mail.com>";

        } elseif($Purpose == "Customer") {
                $mailTo="Name2 <name2@mail.com>, Name3 <name3@mail.com>";
        } else {
        //proably won't be in here
                $mailTo="name5@mail.com";
        }
}

if(!preg_match("/^([0-9a-zA-Z]([-.w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-w]
*[0-9a-zA-Z].)+[a-zA-Z]{2,9})$/",$_POST["Email"])) {
//email address is invalid
die("Invalid Email");
}

if(!empty($message)){ // only send if the form has been filled out.
  $mailHeaders="From : $Name [$Email]";
  $mailSubject="$Purpose from $Name";
  $mailBody="Sent by $Name ($Email) on " . date('M j,Y h:i:s') . " \n\n";
  $mailBody.="Message : \n\n $message";

  mail($mailTo, $mailSubject, $mailBody, $mailHeaders);
  echo "<b>Your email has been sent!</b><br>";
}


echo('<form name="email_form" method="post">
<input type="hidden" name="require" value="Name,Email,Purpose,Comments">
<table>
<tr>
    <td align="right">Name:</td>
    <td><input name="Name" size="25"></td>
</tr>

<tr>
    <td align="right">E-mail:</td>
    <td><input name="Email" size="25"></td>
</tr>
<tr>
    <td align="right">Purpose:</td>
    <td><select name="Purpose">
    <option value="General">General
    <option value="Customer">Customer
    </select>
    </td>
</tr>

<tr>
    <td align="right">Comments:</td>
    <td><textarea name="Comments" rows="10" cols="40"></textarea>
    </td>
</tr>

<tr>
    <td colspan="2" align="center"><input type="submit" value="Submit" name="ema
il_form">
    <input type="reset" value="Reset" name="reset"></td>
</tr>
</table>
</form>');
?>

[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.