[PHP Help] Simple E-mail Form

ouchthathurts

Power Member
Joined
Feb 16, 2011
Messages
622
Reaction score
812
Hey guys,

Was wondering if someone could help me turn this html code into a working php script that emails me the details, I dont need to worry about captcha because I have a content lock box that pops up after they click submit.

Code:
<div class="sign-up-form">
                <p>Sign up for this awesome service, <em>it'll only take a second!</em></p>
                    <ul>
                        <li><label>First Name</label>
                        <input type="text" /></li>
                        <li><label>Last Name</label>
                        <input type="text" /></li>
                        <li><label>Email Address</label>
                        <input type="text" /></li>
                        <li><label>Website</label>
                        <input type="text" /></li>
                    </ul>


Any help would be greatly appreciated as my coding skills are minimum

*Edit* Wow wrong section no idea how that happened - Mods could you move this over to PHP, Sorry!
 
Code:
<?php
if(isset($_POST["submit"])) {
$firstName = htmlspecialchars(trim($_POST["firstName"]));
$lastName = htmlspecialchars(trim($_POST["lastName"]));
$email = htmlspecialchars(trim($_POST["email"]));
$website = htmlspecialchars(trim($_POST["website"]));

$message = "First name: ".$firstName."\n Last Name: ".$lastName."\n Email: ".$email."\n Website: ".$website;

mail("yourEmail", "Some Subject", $message);  
}

?>
<div class="sign-up-form">
    <form action="" method="POST">
                <p>Sign up for this awesome service, <em>it'll only take a second!</em></p>
                    <ul>
                        <li><label>First Name</label>
                        <input type="text" name="firstName" /></li>
                        <li><label>Last Name</label>
                        <input type="text" name="lastName" /></li>
                        <li><label>Email Address</label>
                        <input type="text" name="email" /></li>
                        <li><label>Website</label>
                        <input type="text" name="website" /></li>
                        <input type="submit" name="submit" value="Submit" />
                    </ul>
    </form>

Hope this'll help you. =)
 
Wow thanks for the code !

I just tested it and it looks great fits in perfectly with my theme but no email was sent!

any ideas? I replaced mail("yourEmail", "Some Subject", $message); with my email address
 
did you replace the whole line?
like:
mail("[email protected]");
or just the part you are supposed to like
mail("[email protected]", "Some Subject", $message);

?
else, maybe tell us if there was any error code.
or try this, and tell me if "Email Sent" shows up on your screen:

Code:
<?php
if(isset($_POST["submit"])) {
$firstName = htmlspecialchars(trim($_POST["firstName"]));
$lastName = htmlspecialchars(trim($_POST["lastName"]));
$email = htmlspecialchars(trim($_POST["email"]));
$website = htmlspecialchars(trim($_POST["website"]));

$message = "First name: ".$firstName."\n Last Name: ".$lastName."\n Email: ".$email."\n Website: ".$website;

mail("yourEmail", "Some Subject", $message);  
echo "email sent";
}

?>
<div class="sign-up-form">
    <form action="" method="POST">
                <p>Sign up for this awesome service, <em>it'll only take a second!</em></p>
                    <ul>
                        <li><label>First Name</label>
                        <input type="text" name="firstName" /></li>
                        <li><label>Last Name</label>
                        <input type="text" name="lastName" /></li>
                        <li><label>Email Address</label>
                        <input type="text" name="email" /></li>
                        <li><label>Website</label>
                        <input type="text" name="website" /></li>
                        <input type="submit" name="submit" value="Submit" />
                    </ul>
    </form>
 
Wow thanks for the code !

I just tested it and it looks great fits in perfectly with my theme but no email was sent!

any ideas? I replaced mail("yourEmail", "Some Subject", $message); with my email address

Maybe your webhost has disabled the mail(); function?
 
Thanks for the reply.

I changed the line to
mail("[email protected]", "Some Subject", $message);

The form submits but just reloads like I have hit F5, there is no error message

*random edit* 100th post :D
 
if thats the case, maybe you should try writing the info to a file instead...
Code:
<?php
function append($filename, $data) {
		$fh = fopen($filename, 'a');
		fwrite($fh, $data);
		fclose($fh);
	}
if(isset($_POST["submit"])) {
$firstName = htmlspecialchars(trim($_POST["firstName"]));
$lastName = htmlspecialchars(trim($_POST["lastName"]));
$email = htmlspecialchars(trim($_POST["email"]));
$website = htmlspecialchars(trim($_POST["website"]));

$message = "First name: ".$firstName."\n Last Name: ".$lastName."\n Email: ".$email."\n Website: ".$website;

append("file.txt",$message."\n");
echo "Data was written";
}

?>
<div class="sign-up-form">
    <form action="" method="POST">
                <p>Sign up for this awesome service, <em>it'll only take a second!</em></p>
                    <ul>
                        <li><label>First Name</label>
                        <input type="text" name="firstName" /></li>
                        <li><label>Last Name</label>
                        <input type="text" name="lastName" /></li>
                        <li><label>Email Address</label>
                        <input type="text" name="email" /></li>
                        <li><label>Website</label>
                        <input type="text" name="website" /></li>
                        <input type="submit" name="submit" value="Submit" />
                    </ul>
    </form>
 
Grrr, my false in this post.

Just use wkrappen91's way if the mail() doesn't work. But you need to be careful with the file naming, cause if someone find it, there'll be a new thread with title "Sell email list - good price!". =)
 
Last edited:
Still no luck, doesnt seem to want to do anything just clears the data when i hit submit no file saved no email sent

*EDIT*

It saved and it sends!!!! I'm in idiot I saved the file as .html instead of .php!!


Once again the users at blackhatworld save the day!!
 
Last edited:
Back
Top