Page 1 of 1
Form sending subject and body
Posted: Sat Nov 26, 2005 10:01 pm
by MartinaL
I am using this small form in my php file to send one line of data to my email address;
Code: Select all
<form action="mailto:contact@dhopec.com?subject=Add email to mailing list&" method="post" name="emailform">
<input name="email" type="text" maxlength="40" value="">
<input type="submit" value="Submit">
</form>
It sends with the subject ok, but the input (the email field) is sent in an attached file. How can I get it to display in the body of the email that is sent?
HawleyJR:
Please use tags when posting code.
viewtopic.php?t=21171
Posted: Sun Nov 27, 2005 1:34 am
by php_wiz_kid
Why not just use the PHP mail() function? I've heard that it is better to handle e-mail server side. The script is real easy:
Code: Select all
$to = "contact@dhopec.com";
$subject = "Add email to mailing list";
$message = $_POST['email'];
mail($to, $subject, $message);
Optionaly you can send headers along with the e-mail. A header could contain a from address, or a repy-to address, or even an x-mailer (among many other things). Here's the PHP documentation:
http://us2.php.net/manual/en/ref.mail.php
I hope this helps out.
Posted: Sun Nov 27, 2005 2:16 am
by MartinaL
So if this is what i have at the moment;;
<form action="mailto:
contact@dhopec.com?subject=Add email to mailing list&" method="post" name="emailform">
<input name="email" type="text" maxlength="40" value="">
<input type="submit" value="Submit">
</form>
What do i take out and where do i add this php code?
Posted: Sun Nov 27, 2005 2:37 am
by shiznatix
the code would look somthing like this
Code: Select all
if (!empty($_POST['email']))
{
$to = 'your_email_here@domain.com';
$subject = 'Mailing List Addition';
$message= $_POST['email'].' - has sent you a message';
mail($to, $subject, $message);
echo 'E-mail sent.';
}
else
{
?>
<form action="this_website.php" method="post">
E-mail:<input type="text" name="email"><br>
<input type="submit" name="submit" value="submit">
</form>
<?
}
Sami | fixed function name typo