PDA

View Full Version : Sender field in forms



Saekiz
04-30-2007, 08:47 AM
Hi,

I'm struggling with a form on my site atm.

My question is: How do I make it so that the email adress the users type into the field shows up as the sender when I recieve the email with the inputs from the form?

Hope you can help me..

- Saekiz

tech_support
04-30-2007, 09:08 AM
You need a server-side capable server to do this (eg. PHP)

Saekiz
04-30-2007, 09:10 AM
Hmm.. I think my site should be able to do this..

I'm using e107 as CMS and sending through a cgi-bin sender..

- Saekiz
www.knights-nomads.dk

tech_support
04-30-2007, 09:21 AM
Ah, ok.
It looks like you can.

Try this example:


<?php
if (isset($_POST['Submit'])) {
$em = $_POST;
$content = '';
foreach ($em as $s) {
$content .= $s;
$content .= "\r\n\r\n";
}
mail('youraddress@example.com','Subject',$content);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Mail the form</title>
</head>

<body>
<form name="form" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<p><label>Name: <input type="text" name="name"></label></p>
<p><label>Age: <input type="text" name="age"></label>
</p>
<p>Sex:
<select name="sex">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</p>
<p>Comments:
<p>
<textarea cols="50" rows="10" name="comments"></textarea>
<p>
<label>
<input type="submit" name="Submit" value="Submit">
</label>
</p>
</form>
</body>
</html>

Saekiz
04-30-2007, 01:55 PM
Thats a nice example.. But where do the user type in their email adress?

warandchaos
04-30-2007, 01:59 PM
personally, i suggest using cgi mail form utillity offered by a lot of hosts.

boogyman
04-30-2007, 02:01 PM
put it in your form, just as a text input


<input type="text" name="email" value="" />

and you can add other things to your form as well... the way he set up the processing email, it loops thru the email and puts all the contents into the email section

Twey
04-30-2007, 03:08 PM
But to make it actually appear to be from that person, you'd have to do:
mail('youraddress@example.com','Subject',$content, "From: {$_POST['email']}\r\n");

tech_support
05-01-2007, 06:08 AM
put it in your form, just as a text input


<input type="text" name="email" value="" />

and you can add other things to your form as well... the way he set up the processing email, it loops thru the email and puts all the contents into the email section
That's XHTML.

Try this:


<?php
if (isset($_POST['Submit'])) {
$em = $_POST;
$content = '';
foreach ($em as $s) {
$content .= $s;
$content .= "\r\n\r\n";
}
mail('youraddress@example.com','Subject',$content);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Mail the form</title>
</head>

<body>
<form name="form" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<p><label>E-Mail: <input type="text" name="email"></label></p>
<p>
<label>
<input type="submit" name="Submit" value="Submit">
</label>
</p>
</form>
</body>
</html>

boxxertrumps
05-02-2007, 02:57 AM
instead of this:

$content = "";
foreach ($em as $s) {
$content .= $s;
$content .= "\r\n\r\n";
}
have this:

$s = "\r\n\r\n";
$content = implode($s,$em) .$s;
Its a much neater solution.