Forum Moderators: coopster
When people land on my page the contact.php page even if it's empty i still get an empty email.. i tried to use javascript sure it worked but if u refresh the contact.php page i still get another email.
This is what i want help with if someone is willing to help me. Is there a way i can add an if statement in this code like saying if ($name and $email is empty dont send email?
where would i put the IF statements would i put it in the html portion or the php portion?
THANK YOU IN ADVANCED!
this is the code my friend gave me to use as a email script..
<?php
// Gets the ip address of the person submiting the form
if (getenv(HTTP_CLIENT_IP))
{
$user_ip=getenv(HTTP_CLIENT_IP);
}
else
{
$user_ip=getenv(REMOTE_ADDR);
}
// If server uses php version 4.2 or above
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$comments = $_POST['comments'];
// If server doesn't use php version 4.2 or above
//$name = $HTTP_POST_VARS['name'];
//$company = $HTTP_POST_VARS['company'];
//$email = $HTTP_POST_VARS['email'];
//$telephone = $HTTP_POST_VARS['telephone'];
//$comments = $HTTP_POST_VARS['comments'];
$emailbody="Contact Sender's Information:\n====================\n\n";
$emailbody.="Company:\n$name\n\n";
$emailbody.="Address:\n$address\n\n";
$emailbody.="City:\n$city\n\n";
$emailbody.="Province:\n$province\n\n";
$emailbody.="Telephone:\n$telephone\n\n";
$emailbody.="Email:\n$email\n\n";
$emailbody.="Item 1:\n$item1\n\n";
$emailbody.="Item 2:\n$item2\n\n";
$emailbody.="Agree:\n$agree\n\n";
$emailbody.="Browser:\n$HTTP_USER_AGENT\n\n";
$emailbody.="IP Address:\n$user_ip";
mail ("\n$email", "Contact Us Info", "$emailbody", "From: $name");
$comments = nl2br($comments);
?>
<html>
<body>
<b>Company:</b> <?php print $company;?><br>
<b>Address:</b> <?php print $address;?><br>
<b>Postal Code:</b> <?php print $code;?><br>
<b>City:</b> <?php print $city;?><br>
<b>Province:</b> <?php print $province;?><br>
<b>Phone Number:</b> <?php print $number;?><br>
<b>Email:</b> <?php print $email;?><br>
<b>Item 1:</b> <?php print $item1;?><br>
<b>Item 2:</b> <?php print $item2;?><br>
<b>Terms:</b> <?php print $agree;?><br>
</body>
</html>
Change this :
mail ("\n$email", "Contact Us Info", "$emailbody", "From: $name");
$comments = nl2br($comments);
to this :
if(($emaill) && ($name))
{
mail ("\n$email", "Contact Us Info", "$emailbody", "From: $name");
$comments = nl2br($comments);
}
----
That should do it. Let me know if I've messed something up or left something out, with what ever you have to send that type of thing.. I see a check box here which will send emails on reply.. I'll check that until it gets too much to handle.
Glenn Hefley
it's a html page action = "if.php" so it's going there but i did what u said i might of done it totally wrong but this is my original i changed some things to make it shorter.
if u could help i would appreciate it.
thanks
[edited by: jatar_k at 7:04 pm (utc) on Feb. 19, 2004]
[edit reason] no personal urls thanks [/edit]
Just got home and took a look at this.. I know this is going to sound like I'm backing out, but.. this isn't a quick fix, this is a re-write. The file you have here is straight shot cold, and I would have to spend more time on it than I'm willing to right now.
Personally I would go back to the guy who wrote this for you and ask him/her to clean it up and make it work right. I can't imagine putting together a code I'm selling to someone, without a simple error check like that.
Maybe I'm just tired and cranky, and someone else can do it for you, but I thought I might be puting in an if statment somewhere, and sending it back. This needs a few more things than that. Probably about a half hour, but that's more time than I have right now.
Glenn Hefley