0

Hi All - I have a form and I want the two places in which the enquirer types their email adress in (Field emailAddress and email2) to check that the email address values are the same and send the form - if not the same just say some kind of error message eg your email address does not match... blah

Im struggling and have tried and failed, it may just be that I dont know at what point to insert a compare type php string. All suggestions will be most appreciated.

<?php

if(isset($_POST['name']))
{
	$to  = 'me@adomain.com';
	// subject
	$subject = 'Website enquiry';
	// message
	$message = '
	<html>
	<head>
	  <title>Website Enquiry</title>
	</head>
	<body>
	  <table>
		<tr>
		  <td>Name : </td><td>&nbsp;&nbsp;'.$_POST['name'].'</td>
		</tr>
		<tr>
		<td>Company Name : </td><td>&nbsp;&nbsp;'.$_POST['coName'].'</td>
		</tr>
		<tr>
		  <td>Email Address : </td><td>&nbsp;&nbsp;'.$_POST['emailAddress'].'</td>
		</tr>
		<tr>
		  <td>Confirm Email address : </td><td>&nbsp;&nbsp;'.$_POST['email2'].'</td>
		</tr>
		<tr>
		<tr>
		  <td>Contact Tel No : </td><td>&nbsp;&nbsp;'.$_POST['contactNo'].'</td>
		</tr>
		<td>How you found us : </td><td>&nbsp;&nbsp;'.$_POST['findUs'].'</td>
		</tr>
		<tr>
		  <td>Message : </td><td>&nbsp;&nbsp;'.$_POST['message'].'</td>
		</tr>
		
	  </table>
	</body>
	</html>
	';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '. $_POST['emailAddress'] . "\r\n";


// Mail it
@mail($to, $subject, $message, $headers);
//header("Location:index.html");
?>
<script type='text/javascript'>
alert("Thank you for your details. We will respond to your enquiry promptly.");
window.location.href="Contact.html";
</script>
<?php

}
?>
3
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by sjgoodjob
0

I have made some mods to your code, that should do it.

<?php

if (isset($_POST['name'])) {
    /** Add the check here! **/
    if ($_POST['emailAddress'] != $_POST['email2']) {
        //the email addresses are not the same, do something
        echo "E-mail mismatch";
        //you can also add html codes here
    } else {
        $to = 'me@adomain.com';
        // subject
        $subject = 'Website enquiry';
        // message
        $message = '
    <html>
    <head>
      <title>Website Enquiry</title>
    </head>
    <body>
      <table>
        <tr>
          <td>Name : </td><td>&nbsp;&nbsp;' . $_POST['name'] . '</td>
        </tr>
        <tr>
        <td>Company Name : </td><td>&nbsp;&nbsp;' . $_POST['coName'] . '</td>
        </tr>
        <tr>
          <td>Email Address : </td><td>&nbsp;&nbsp;' . $_POST['emailAddress'] . '</td>
        </tr>
        <tr>
          <td>Confirm Email address : </td><td>&nbsp;&nbsp;' . $_POST['email2'] .
            '</td>
        </tr>
        <tr>
        <tr>
          <td>Contact Tel No : </td><td>&nbsp;&nbsp;' . $_POST['contactNo'] . '</td>
        </tr>
        <td>How you found us : </td><td>&nbsp;&nbsp;' . $_POST['findUs'] . '</td>
        </tr>
        <tr>
          <td>Message : </td><td>&nbsp;&nbsp;' . $_POST['message'] . '</td>
        </tr>

      </table>
    </body>
    </html>
    ';

        // To send HTML mail, the Content-type header must be set
        $headers = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= 'From: ' . $_POST['emailAddress'] . "\r\n";


        // Mail it
        @mail($to, $subject, $message, $headers);
        //I have moved the html codes into this block of else

?>
<script type='text/javascript'>
alert("Thank you for your details. We will respond to your enquiry promptly.");
window.location.href="Contact.html";
</script>
<?php
    }
}
?>

Edited by mike_2000_17: Fixed formatting

0

I have made some mods to your code, that should do it.

<?php

if (isset($_POST['name'])) {
    /** Add the check here! **/
    if ($_POST['emailAddress'] != $_POST['email2']) {
        //the email addresses are not the same, do something
        echo "E-mail mismatch";
        //you can also add html codes here
    } else {
        $to = 'me@adomain.com';
        // subject
        $subject = 'Website enquiry';
        // message
        $message = '
	<html>
	<head>
	  <title>Website Enquiry</title>
	</head>
	<body>
	  <table>
		<tr>
		  <td>Name : </td><td>&nbsp;&nbsp;' . $_POST['name'] . '</td>
		</tr>
		<tr>
		<td>Company Name : </td><td>&nbsp;&nbsp;' . $_POST['coName'] . '</td>
		</tr>
		<tr>
		  <td>Email Address : </td><td>&nbsp;&nbsp;' . $_POST['emailAddress'] . '</td>
		</tr>
		<tr>
		  <td>Confirm Email address : </td><td>&nbsp;&nbsp;' . $_POST['email2'] .
            '</td>
		</tr>
		<tr>
		<tr>
		  <td>Contact Tel No : </td><td>&nbsp;&nbsp;' . $_POST['contactNo'] . '</td>
		</tr>
		<td>How you found us : </td><td>&nbsp;&nbsp;' . $_POST['findUs'] . '</td>
		</tr>
		<tr>
		  <td>Message : </td><td>&nbsp;&nbsp;' . $_POST['message'] . '</td>
		</tr>
		
	  </table>
	</body>
	</html>
	';

        // To send HTML mail, the Content-type header must be set
        $headers = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= 'From: ' . $_POST['emailAddress'] . "\r\n";


        // Mail it
        @mail($to, $subject, $message, $headers);
        //I have moved the html codes into this block of else

?>
<script type='text/javascript'>
alert("Thank you for your details. We will respond to your enquiry promptly.");
window.location.href="Contact.html";
</script>
<?php
    }
}
?>

Edited by logbon72: n/a

0

i think you should check the email use javascript

<SCRIPT LANGUAGE=javascript RUNAT=Server>
function isEmail(strEmail) {
if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
return true;
else
alert("oh");
}
</SCRIPT>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.