Need PHP mail form! Please :(

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Jeefo
Forum Newbie
Posts: 16
Joined: Thu Jun 16, 2005 3:38 pm
Location: Tokyo, Japan

Need PHP mail form! Please :(

Post by Jeefo »

I desperatly need a PHP mail form script. It NEEDS to make sure that the person entering in their email address is infact, a real email address. Also, it needs to have their IP address sent to me. If you make one, or point me in the direction of one, I will be most greatful.

I need this because someone (or multiple people) keep spamming me with the contact form at my website.

Thank you all, and again I will be most greatful.
sticksys
Forum Commoner
Posts: 33
Joined: Thu Aug 18, 2005 3:23 am
Location: Isreal
Contact:

Post by sticksys »

O.K i never give something free, but there is always the first time ;)


i'll give you an example:

Code: Select all

<html>
	<head>

		<title>Contact Form</title>
	</head>
<body>
<?
if(!$_POST['name'])
{
?>
<form action="<? $_SERVER['PHP_SELF']; ?>" method="post">
<table dir="ltr" style="width: 850px;">
                <tr>
                        	 <td>
                        	 Your name:  
                        	 </td>
                         	 <td>
		<input type="text" name="name" />
		</td>
                </tr>
	<tr>
		<td>
		Subject: 
		</td>
		<td>
		<input type="text" name="subject" style="width: 150px;" />
		</td>
	</tr>
	<tr>
		<td valign="top">
		Your Message:
		</td>
		<td>
		<textarea cols="40" rows="10" name="MsgBody" />
		</td>
	</tr>
	<tr>
		<td colspan="2">
		* Your IP will recorded!
		</td>
	</tr>
	<tr>
		<td>
		<input type="submit" value="submit" />
		</td>
	</tr>
</table> 
</form>
<?
}
else
{

if($_POST['name'] == NULL || $_POST['subject'] == NULL || $_POST['MsgBody'])
{
	die("Please complete the form.");
}
else
{
          mail("YOURMAIL@YOURDOMAIN.COM","{$_POST['subject']}","
	Your Name: {$_POST['name']}
	Your Subject: {$_POST['subject']}
	Your Message:
 	{$_POST['MsgBody']}
	
	User IP: {$_SERVER['REMOTE_ADDR']}
	
	");

	echo "Your mail has been sent, one of the administartors will replay soon.";
}

}
?>
</body>

</html>












hope it helps =]
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

By a "real email address" do you mean simply formatted like whatever@website.com?

If so, take a look at ereg() and regex from the manual.
sticksys
Forum Commoner
Posts: 33
Joined: Thu Aug 18, 2005 3:23 am
Location: Isreal
Contact:

Post by sticksys »

User http://php.net/preg_match and check if it includes the basic form [ (S+)@(S+).(S+) ]....
Post Reply