e-mail validation

the mail() function

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 9
Joined: Thu Mar 02, 2006 6:07 pm

e-mail validation

Postby vietboy505 » Thu Mar 02, 2006 7:27 pm

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: Select all


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

*[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">
    <td align="right">Name:</td>
    <td><input name="Name" size="25"></td>

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

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

    <td colspan="2" align="center"><input type="submit" value="Submit" name="ema
    <input type="reset" value="Reset" name="reset"></td>


User avatar
New php-forum User
New php-forum User
Posts: 243
Joined: Wed Feb 01, 2006 9:18 am
Location: Netherlands

Postby Coditor » Fri Mar 03, 2006 2:15 am


A few issues:

• determineEmail is never called
• determineEmail doesn't return a value and cannot change the $mailTo variable because it's not global
• you're using $Name, $Email etc which only works if register_globals is on. Otherwise you have to use $_POST{"Name"} and $_POST{"Email"}
• I think the header should be "From: $Name <$Email>" - with <> instead of []


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 2 guests