...

View Full Version : Submitting Form Data to email?



Vapor
05-05-2007, 11:02 PM
I have a friend who said that you can submit data that people input into a form using the mailto function, is this true? I would like to do this without having to use a database.

Is there a javascript that could do this?...

Thanks

PappaJohn
05-06-2007, 12:01 AM
Yes, this is certainly possible. The user's input would be sent to an email address you specify, and it would then be up to you to deal with that input.

Javascript isn't my strongest language, so I won't comment on that, but this could easily be accomplished using the mail() function in php.

More information (http://www.php.net/manual/en/function.mail.php) on php's mail().

Vapor
05-06-2007, 01:44 AM
Can you give me an example of that code? I was hoping to do this by using the html mailto function, not php. Php is a server side language, and I wanted to know if this could be done client side.

_Aerospace_Eng_
05-06-2007, 01:55 AM
Can you give me an example of that code? I was hoping to do this by using the html mailto function, not php. Php is a server side language, and I wanted to know if this could be done client side.

Not reliably. Not everyone has a mail client setup to send email which is why the server side method is preferred. The php mail() function doesn't use a database. As for an example we don't have time to give everyone a simple example. There are many resources out there on the php mail() function. Check out www.hotscripts.com or www.joe2torials.com

PappaJohn
05-06-2007, 02:00 AM
It may well be possible with Javascript - that's just not for me to answer.

Anyway, here's an example that accepts a user's name and email address and sends it to the address you specify.

HTML:


<form action="http://yoursite.com/submitform.php" method="post">
<div>
Enter name: <input type="text" name="username" size="30" value=""><br />
Enter email address: <input type="text" name="email" size="30" value=""><br /><br />
<input type="submit" name="go" value="Submit Data">
</div>
</form>


submitform.php:


<?php
// get user input
$username = $_POST['username'];
$useremail = $_POST['email'];


// send email confirmation
$to = 'Me <me@myemail.com>';

$subject = 'User Input Data';

$message = 'Username: ' . $username . '<br />User Email Address: ' . $useremail;

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= 'From: ' . $username . ' <' . $useremail . '>\r\n";

mail($to, $subject, $message, $headers);
?>


You would replace the "$to" email information (in the php) with the intended recipient email, and the "form action=" information (in the html) to point to the php file on your site.

Obviously, this is a very limited example, but you can expand it as needed. I made no effort to format the html, as that would depend on your site.

HTH

Edit: _AE_ answered the client-side question.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum