HTML form to email data to webmaster?

1234

New member
So i currently have it set to where people can enter data. I then have this written :
<form
action="mailto:[email protected]"
method="POST"
enctype="multipart/form-data"
name="test">
First name: <input name="firstname" type="text" />
<br />
Last name: <input name="lastname" />
<br />
</form>

when users click the submit button, it pops up with a window that requires the user to log into their own email to send to the webmaster. I want to be able to have it send the email from my email address to my email address.
any thoughts?
 
The way you're doing it is totally wrong. What you should do instead is to make a server-side script (for instance "sendmail.php") that the users will be directed to when they click the submit button.

For instance, this could be your HTML code:
<form action="sendmail.php" method="POST" enctype="multipart/form-data" name="test">
<p>Name: <input type="text" name="name" /></p>
<p>Email: <input type="text" name="email" /></p>
<p>Subject: <input type="text" name="subject" /></p>
<p><textarea name="message"></textarea></p>
</form>

And your PHP code could be this:
<?php
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];

// validation of email address (optional)

# Send email
mail('[email protected]', $subject, "From: $name ($email)\n\n$message");
?>

But if you use this script, you should first make sure that your PHP installation has an SMTP server to connect to (contact your web hosting company to clarify this).
 
Back
Top