Jump to content

Recommended Posts

Hey Everyone,

 

I have a question, I have a script that allows me to receive messages from my visitors on my site. As it is, its a great script (has captcha protection and works like a charm) but I want to modify it and add an additional check on it. As it is, it notifies my users when a required field is empty (this happens when one hits the submit button) but I also want to it to check an input field, or the email field really. I want it to only accept e-mails from a specific domain (like for example, if the email address field doesnt contain the words @phpfreaks.com I want it to display a notification similar to the empty field one when a user hits submit)

 

In appreciation, please note that I will compensate and deposit a little something via Paypal to a user that might help me accomplish this as my way of saying thanks.

 

Here's the script:

<?php

if($image_verification) 
{
require_once("{$path_escape}captcha.cls.php");
$captcha = new captcha();
}

$data = array();

if ($_POST['do'] == "post")
{
$data = $_POST;

$value_missing = FALSE;
if(!$data['name'] || !$data['email'] || !$data['message']) {
	$err .= "• $lang[ERROR_POST_FILL_ALL]<br>";
	$value_missing = TRUE;
}
if($image_verification && !$captcha->verify($_POST['captcha']))
	$err .= "• $lang[ERROR_IMAGE_VERIFICATION_FAILED]<br>";
if($data['email'] && !ValidateEmail($data['email']))
	$err .= "• $lang[ERROR_INVALID_EMAIL]<br>";

}

if ($_POST['do'] == "post" && !$err)
{
if($image_verification)
	$captcha->resetCookie();

$msg = "";
$msg .= "Name: ".$data['name']."\n";
$msg .= ($data['phone']) ?
	"Phone: ".$data['phone']."\n\n" : "";
$msg .= "Message:\n~~~~~~~~~~~~~~\n";
$msg .= $data['message'];

if (!@sendMail($site_email, $contact_form_subject, 
		$msg, $data['email']))
/* End Version 5.1 - Send mail using SMTP */
{
	if($debug) echo "<p>Error sending contact message.</p>";
	else die("Error sending confirmation mail");
}
else
{
	header("Location: /index.php?view=thanks");
}
}

?>
<div>

    <h2>Contact Us</h2>
    
    <a href="index.php?cityid=<?php echo $xcityid; ?>"><?php echo $lang['BACK_TO_HOME']; ?></a>

<br><br>Thank you so much for visiting <?php echo $site_name; ?>. Please write to us by filling out the form below.<br><br>

<?php if($err) echo "<br><div class=\"err\">$err</div><br>"; ?>

<form method="post" name="frmPost">
<table class="postad" border="0" cellspacing="0" cellpadding="0">

	<tr>
		<td colspan="2">
			<b>Name:</b> <span class="marker">*</span><br>
			<input name="name" type="text" size="60" maxlength="100" value="<?php echo $data['name']; ?>">
		</td>
	</tr>

	<tr>
		<td colspan="2">

			<b>Email:</b> <span class="marker">*</span><br>
			<input name="email" type="text" size="60" maxlength="100" value="<?php echo $data['email']; ?>">

		</td>
	</tr>

	<tr>
		<td colspan="2">

			<b>Phone:</b> <br>
			<input name="phone" type="text" size="60" maxlength="100" value="<?php echo $data['phone']; ?>">

		</td>
	</tr>		

	<tr><td colspan="2"> </td></tr>

	<tr>
		<td colspan="2">

			<b>Message:</b> <span class="marker">*</span><br>
			<textarea name="message" cols="78" rows="10" ><?php echo $data['message']; ?></textarea><br>

		</td>
	</tr>

	<?php
	if(!$in_admin && $image_verification)
	{
	?>
		<tr><td colspan="2"> </td></tr>
		<tr>
			<td valign="top"><b><?php echo $lang['POST_VERIFY_IMAGE']; ?>: <span class="marker">*</span></b></td>
			<td>
			<img src="captcha.png.php?<?php echo rand(0,999); ?>"><br>
			<span class="hint"><?php echo $lang['POST_VERIFY_IMAGE_HINT']; ?></span><br>
			<input type="text" name="captcha" value="">
			</td>
		</tr>

	<?php
	}
	?>

</table>
<input name="do" type="hidden" id="do" value="post">
<button type="submit" class="btn_post">SUBMIT</button>
</form>

</div>

 

Lastly and for fyi really, the notification im gonna use in my language file for this email error will be

 

$lang[ERROR_USE_EMAIL_FROM_THIS_DOMAIN]

 

so you can be bring it up like this  if you know what I mean

 

$err .= "• $lang[ERROR_USE_EMAIL_FROM_THIS_DOMAIN]<br>";

 

But ya, any help will greatly be appreciated.

 

Thanks and god bless  :shy:

 

- STG

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.