PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
aikman
Forum Newbie
Posts: 1 Joined: Sat May 22, 2004 11:56 am
Post
by aikman » Sat May 22, 2004 11:56 am
I want to get all the variables from the form and then send them in a mail. I want to send the mail in the same PHP page as the form is located.
Here's the form:
Code: Select all
<form>
<table width="594" border="1">
<tr>
<td width="147" height="19">Naam:</td>
<td width="359"><input name="naam" type="text" id="naam" size="70"></td>
</tr>
<tr>
<td>Straat en nummer:</td>
<td><input name="straat" type="text" id="straat" size="70"></td>
</tr>
<tr>
<td>Postcode:</td>
<td><input name="postcode" type="text" id="postcode" size="70"></td>
</tr>
<tr>
<td>Gemeente:</td>
<td><input name="gemeente" type="text" id="gemeente" size="70"></td>
</tr>
<tr>
<td>Email-adres:</td>
<td><input name="email" type="text" id="email" size="70"></td>
</tr>
<tr>
<td>Tel. of GSM-nummer: </td>
<td><input name="telefoon" type="text" id="telefoon" size="70"></td>
</tr>
<tr>
<td colspan="2"><input name="button" onClick:'mailFunction' value="Bestelling verzenden per email"></td>
</tr>
</table>
</form>
So when the button is clicked the mailFunction should start. How do you define a function in PHP?
So the mail function should be something like this:
Code: Select all
<?php
/* recipients */
$to = "mary@example.com" . ", " ; // note the comma
$to .= "kelly@example.com";
/* subject */
$subject = "User info";
/* message */
$message = '
<html>
<body>
Naam: <? echo _GET[naam];?> /* How do you get that form variable???*/
Straat: <? echo _GET[straat];?>
and so on...
</body>
</html>
';
/* and now mail it */
mail($to, $subject, $message);
?>
Can anyone help me with this code?
Thanks
launchcode
Forum Contributor
Posts: 401 Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:
Post
by launchcode » Sat May 22, 2004 12:03 pm
I would suggest mailing the form values before you echo the HTML out. But to answer your question, if the form was POSTED (method=post) then use:
$name = $_POST['naam'];
and if the form wasn't using the post method, use this:
$name = $_GET['naam'];
(the quotes are important).
zoidberg
Forum Newbie
Posts: 4 Joined: Sat May 22, 2004 11:31 am
Location: Canada
Post
by zoidberg » Sat May 22, 2004 12:08 pm
Here's a simple I wrote awhile ago.
I doubt if it's rfc compliant or whatever, but it works well.
Like I said it's very simple but a good place to start.
Feedback Form Processor:
<?
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$subject=$_POST['subject'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$comments=$_POST['comments'];
mail("recipient here","$subject","Sender: $firstname $lastname\n$email\n $phone\nMessage: $comments","From: $email\r\n");
header("Location: thx.php");
?>
Nay
Forum Regular
Posts: 951 Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia
Post
by Nay » Sat May 22, 2004 12:15 pm
Just on the note, here's a neater way you can write the message:
Code: Select all
/* message */
$message = <<< MSG
<html>
<body>
hello, my name is
{$_POST['naam']}
and my number's
{$_POST['telefoon']}
</body>
</html>
MSG;
hope it helps,
-Nay