473,395 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Contact Us script

Hello,

I'm relatively new to PHP so I found this free contact us script on
the net that i was going to use for my Contact Us php page. Its works
pretty good except for error handling. I was wondering if any can
hlep me understand what is missing. I've posted the php files below
below. Contact.php calls the sendemail.php script. This appears to be
the validation code in the sendemail.php file. But i would like it to
validate and prefer a pop up box instead on the Contact.php page
before contining to the confirmation page (sendemail.php). Any help
would be appreciated.

Al

<?php
if(!$visitormail == "" && (!strstr($visitormail,"@") || !
strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
}
if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Use Back - fill in all fields</h2>\n";
}

==========================CONTACT,PHP============= ================
<table width="100%" cellpadding="5" border="2">
<tr><td><form method="post" action="sendemail.php">
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>

<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?
>" />
Your Name:<br />
<input type="text" name="visitor" size="35" />
<br />
Your Email Address:<br />
<input type="text" name="visitormail" size="35" />
<br />
<br />
Attention:<br />
<select name="attn" size="1">
<option value=" General Support ">General Inquiries </option>
<option value=" Sales n Billing ">Sales & Billing </option>
<option value=" Technical Support ">Technical Support </option>
<option value=" Webmaster ">Webmaster </option>
</select>
<br /><br />
Message:
<br />
<textarea name="notes" rows="25" cols="49"></textarea>
<br />
<input type="submit" value="Send Mail"/>
<br />
</form></tr></td>
</table>
==============================END OF SCRIPT======================

=====================SENDEMAIL.PHP script=========================
<?php
$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];
?>

<?php
if(!$visitormail == "" && (!strstr($visitormail,"@") || !
strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
}
if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Use Back - fill in all fields</h2>\n";
}

$todayis = date("l, F j, Y, g:i a") ;
$attn = $attn ;
$subject = $attn;
$notes = stripcslashes($notes);
$message = " $todayis [EST] \n
Attention: $attn \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n";

$from = "From: $visitormail\r\n";
mail("in**@yoursite.com", $subject, $message, $from);
?>

<table width=100% cellpadding="10" border="2">
<tr>
<th align="center"><h3Confirmation of Message Sent</h3></th>
</tr>
<tr>
<td>
<b>IP:</b<?php echo $ip ?>
<br />
<b>Attention:</b<?php echo $attn ?>
<br />
<b>From:</b<?php echo $visitormail ?>
<br />
<b>Date:</b<?php echo $todayis ?>
<br />
<br />
Thank you <?php echo $visitor ?>, your message has been sent
successfully. We generally respond to emails within 24-48 hours.
Thanks for contacting us!
<br />
<br />
</td>
</tr>
<tr>
<td align="center">
<a href="/index.php"Home </a>
</td>
</tr>
</table>
=========================END OF SCRIPT==============================

Jun 3 '07 #1
4 3852
thanos wrote:
Hello,

I'm relatively new to PHP so I found this free contact us script on
the net that i was going to use for my Contact Us php page. Its works
pretty good except for error handling. I was wondering if any can
hlep me understand what is missing. I've posted the php files below
below. Contact.php calls the sendemail.php script. This appears to be
the validation code in the sendemail.php file. But i would like it to
validate and prefer a pop up box instead on the Contact.php page
before contining to the confirmation page (sendemail.php). Any help
would be appreciated.

Al
Al,

You can't do popups in PHP. You would need Javascript to do that - and
that adds a whole new layer of complexity.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 4 '07 #2
thanos wrote:
Hello,

I'm relatively new to PHP so I found this free contact us script on
the net that i was going to use for my Contact Us php page. Its works
pretty good except for error handling. I was wondering if any can
hlep me understand what is missing. I've posted the php files below
below. Contact.php calls the sendemail.php script. This appears to be
the validation code in the sendemail.php file. But i would like it to
validate and prefer a pop up box instead on the Contact.php page
before contining to the confirmation page (sendemail.php). Any help
would be appreciated.

Al

<?php
if(!$visitormail == "" && (!strstr($visitormail,"@") || !
strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
}
if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Use Back - fill in all fields</h2>\n";
}

==========================CONTACT,PHP============= ================
<table width="100%" cellpadding="5" border="2">
<tr><td><form method="post" action="sendemail.php">
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>

<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?
>" />

Your Name:<br />
<input type="text" name="visitor" size="35" />
<br />
Your Email Address:<br />
<input type="text" name="visitormail" size="35" />
<br />
<br />
Attention:<br />
<select name="attn" size="1">
<option value=" General Support ">General Inquiries </option>
<option value=" Sales n Billing ">Sales & Billing </option>
<option value=" Technical Support ">Technical Support </option>
<option value=" Webmaster ">Webmaster </option>
</select>
<br /><br />
Message:
<br />
<textarea name="notes" rows="25" cols="49"></textarea>
<br />
<input type="submit" value="Send Mail"/>
<br />
</form></tr></td>
</table>
==============================END OF SCRIPT======================

=====================SENDEMAIL.PHP script=========================
<?php
$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];
?>

<?php
if(!$visitormail == "" && (!strstr($visitormail,"@") || !
strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
}
if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Use Back - fill in all fields</h2>\n";
}

$todayis = date("l, F j, Y, g:i a") ;
$attn = $attn ;
$subject = $attn;
$notes = stripcslashes($notes);
$message = " $todayis [EST] \n
Attention: $attn \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n";

$from = "From: $visitormail\r\n";
mail("in**@yoursite.com", $subject, $message, $from);
?>

<table width=100% cellpadding="10" border="2">
<tr>
<th align="center"><h3Confirmation of Message Sent</h3></th>
</tr>
<tr>
<td>
<b>IP:</b<?php echo $ip ?>
<br />
<b>Attention:</b<?php echo $attn ?>
<br />
<b>From:</b<?php echo $visitormail ?>
<br />
<b>Date:</b<?php echo $todayis ?>
<br />
<br />
Thank you <?php echo $visitor ?>, your message has been sent
successfully. We generally respond to emails within 24-48 hours.
Thanks for contacting us!
<br />
<br />
</td>
</tr>
<tr>
<td align="center">
<a href="/index.php"Home </a>
</td>
</tr>
</table>
=========================END OF SCRIPT==============================
I have briefly gone over the code you posted and there seem to be
several problems with it.

- email validation could still let an invalid mail go through. Better
use regexp for this
- there is nothing to stop the script from executing mail() if the
validation fails. Basically you just show the error message and merrily
go about trying to send the mail. A simple yet ugly solution would be to
insert a die() after an error was encountered.
- client-side validation, which you seem to be asking for, is usually
done using JavaScript. however never rely solely on client-side
validation as it can be tampered with (or not work at all if the client
browser has javascript turned off). that means while it may be nice of
you to implement it, you still have to have the server-side validation code

Something I might want to do with your code regarding the user interface
and error checking

- copy all the $_POST data into $_SESSION if error occurs, add a
$_SESSION["error"] = 1 as a flag. Also add a $_SESSION["messages"] with
all the error messages generated while validating
- do something along the lines of
header("Location: contact.php");
die()
after validation if any of the validation conditions have failed
The validation code might look like

$_SESSION["messages"] = "";
$errorflag = 0;

if () // email not valid
{
$_SESSION["messages"] .= "Email-invalid<br />";
$errorflag = 1;
}
if () // visitor name empty
{
$_SESSION["messages"] .= "Visitor name empty!<br />";
$errorflag = 1;

}
/*
other ifs
*/

if ($errorflag == 1)
{
$_SESSION["visitor"] = $visitor;
$_SESSION["visitormail"] = $visitormail;
// etc
$_SESSION["error"] = 1;
header("Location: contact.php");
die();
}

// the rest of sendemail.php script

- on contact.php check for existence of $_SESSION["error"], if it is
there print out the $_SESSION["messages"] error messages on an
appropriate location. Then use the saved $_POST members to fill the form
elements so that user does not have to retype everything, i.e. something
like

<input type="text" name="visitormail" value="<?php echo
$_SESSION["visitormail"]; ?>" size="35" />

and unset the session variables

The code is by no means perfect (not even tested) and it should by used
as a reference to what you may want to do. With something like this
implemented, you may decide to go on and implement client side
validation as well, but you're not dependant on your client actually
supporting it or someone deciding to circumvent it.
Jun 4 '07 #3


Jerry:

Wouldn't something like this help him on popups?

if (something)
echo "<script type='text/javascript'alert('something') </
script>";
Jun 7 '07 #4
Phil wrote:
>
Jerry:

Wouldn't something like this help him on popups?

if (something)
echo "<script type='text/javascript'alert('something') </
script>";

Sure, but that's not PHP. It's javascript - and probably won't be shown
until the page is completely loaded.

And it won't show at all if the user don't have javascript enabled.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 7 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: MrMagooba | last post by:
Hi, I have a contact page that, when submit is clicked it checks the inputs then outputs to a "read only" version of the input form fromwhich the email can be sent. How would I go about changing...
9
by: Jason | last post by:
I'm struggling with this email code and I'm not php freak since I'm starting to learn php stuff. Could use some help... It seems that I get too many parse errors all over and cannot figure went...
20
by: Steevo | last post by:
For some reason I can't seem to get the contact form on our website to work any longer. I think I must have something wrong in the script because I keep getting an "Internal Server Error" upon...
0
by: Benjamin Bittner | last post by:
Hallo NG, ive searched a lot in some google groups, and found many threads, but nothing that helped me. Here is the scenario: I have an aspx page which loads a user control in page.onInit like...
1
by: paolazi | last post by:
HI I have a flash templates..that uses php as well now I have a problem with my contact page as follows: the user enter his name, email and message into flash input whose Var are: your_name,...
0
by: Derek Moore | last post by:
Hi any one help with this one below is the "contact.php form" and the contents of the "button "from with in flash! but all i get back is the field names but no content any ideas??? contact.php...
12
by: colt28 | last post by:
Ok so I found an ajax contact form script but i can't get the b****** to work. I made a bunch of alterations to it and it didn't work so i replaced everything with the original and it still didn't...
11
by: snapscan | last post by:
Hello, I am new to PHP code and I have copied the following code from the internet to create a contact page on my web site. <? $subject="from ".$_GET; $headers= "From: ".$_GET."\n"; ...
4
by: tokcy | last post by:
HI every one, i am using tooltip on click of link and i want like when that tooltip open then background window would be blure(). can anyone help me...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.