Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Fleetwood Mac

macrumors 65816
Original poster
Apr 27, 2006
1,265
0
Canada
So I've made this contact form for a site. It look spiffy and fits nicely into the page, but is relatively useless since it doesn't send mail yet.

I guess I'm looking for some sort of PHP code to send out emails when posted to by the form...?
 

Fleetwood Mac

macrumors 65816
Original poster
Apr 27, 2006
1,265
0
Canada
Google search for "php send mail code" returned this sample code ready for consumption. ;)
Well that's nice, but it doesn't quite do what I want. One that checks for a blank form and returns an error when that happens would be great. Is there a way I could go about editing the code to do that? And making the "to" field point to the email address I want the contact form to send mail to without displaying the field in the form?

I've spent a long time Googling and messing with code here, I'm just naturally terrible with PHP.
 

SC68Cal

macrumors 68000
Feb 23, 2006
1,642
0
Your looking for some validation. This should get you started.

Code:
<?php

	if (isset($_POST['email'])){
		//send the e-mail...paste the code here
		echo 'Thank You';
	}
	else{
		echo '<b>You did not enter an e-mail address</b>';
	}
?>
<html>
	<form action="email.php" method="post">
		<input type="text" name="email" />
		<input type="submit" />
	</form>
</html>

Just change the form action to the name of the page so that it POSTs to itself.

Take note that this is for educational purposes. You need some input sanitizing and such before you use this for your actual site.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.