View Full Version : Sending email from a form..
Fleetwood Mac
Sep 24, 2007, 08:14 PM
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...?
tutubibi
Sep 24, 2007, 09:27 PM
Google search for "php send mail code" returned this (http://smartwebby.com/PHP/emailsending.asp) sample code ready for consumption. ;)
Fleetwood Mac
Sep 25, 2007, 12:47 AM
Google search for "php send mail code" returned this (http://smartwebby.com/PHP/emailsending.asp) 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.
CanadaRAM
Sep 25, 2007, 01:19 AM
First step: Check with the host to see what they have for readymade code. (and what versions of things they have on the server).
SC68Cal
Sep 25, 2007, 01:21 AM
Your looking for some validation. This should get you started.
<?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.
Fleetwood Mac
Sep 25, 2007, 04:30 PM
First step: Check with the host to see what they have for readymade code. (and what versions of things they have on the server).
Its my server.
Thanks for the code SC68Cal. I think that should be helpful.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.