Form sending subject and body

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

Post Reply
MartinaL
Forum Newbie
Posts: 10
Joined: Fri Nov 04, 2005 9:31 pm

Form sending subject and body

Post 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
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Post 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.
MartinaL
Forum Newbie
Posts: 10
Joined: Fri Nov 04, 2005 9:31 pm

Post 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?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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
Post Reply