Sending Form Data by Email

  • DymeMedia1
  • Novice
  • Novice
  • User avatar
  • Joined: Dec 17, 2003
  • Posts: 30
  • Loc: London
  • Status: Offline

Post December 22nd, 2003, 8:46 pm

A little help again if possible , im just makin sum forms and wanted to know if you know the form action code to have the information entered send to my email address and pointed to a page please, Thanks again :?
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post December 22nd, 2003, 8:46 pm

  • SniperDevil
  • Beginner
  • Beginner
  • User avatar
  • Joined: Dec 21, 2003
  • Posts: 42
  • Status: Offline

Post December 22nd, 2003, 9:01 pm

use the php mail function to send; and you can format the e-mail using the variables you defined in the script, i.e. the person's name could be $name, so it would send an e-mail to you like NAME: $name, where $name would be the person's name.

Here you will find detailed information and syntax specification for the mail function.
  • RichB
  • Guru
  • Guru
  • User avatar
  • Joined: May 17, 2003
  • Posts: 1121
  • Loc: Boston
  • Status: Offline

Post December 23rd, 2003, 1:11 am

DymeMedia1 wrote:
im just makin sum forms and wanted to know if you know the form action code to have the information entered send to my email address


It is technically possible to put a "mailto:whoever@whoever.com" inside the action attribute of a form, but it's never a good idea because the user will first get a warning about their email address being exposed, then their email client will fire up (assuming they have a default email client setup), and they have to send the actual email containing the form contents. Needless to say, few people are going to go through all that.

Your other options are to install a formmail script on the server that will do most of the work for you once you set it up, or to use the PHP mail function as SniperDevil has suggested if it is available. If you go the formmail route there are a number of freebies available in PHP or Perl that you can download and configure per their instructions.

I'm not an expert at PHP by any means, but I was playing around with the mail() function a while ago and made a little form that submits to itself and emails the data. It doesn't do any kind of validation except to check to see whether the form is being submitted. I'm not suggesting you use it, but it is an example of using the php mail() function. The PHP Manual link that SniperDevil gave you is a good source, and you can find tutorials on the web about the details of using mail() by searching Google.

// outdated script removed - see below
Free Programming Resources
  • DymeMedia1
  • Novice
  • Novice
  • User avatar
  • Joined: Dec 17, 2003
  • Posts: 30
  • Loc: London
  • Status: Offline

Post December 23rd, 2003, 7:02 am

Thanks ill try that out and let you know how it goes if any problems
  • RichB
  • Guru
  • Guru
  • User avatar
  • Joined: May 17, 2003
  • Posts: 1121
  • Loc: Boston
  • Status: Offline

Post December 26th, 2003, 1:19 am

It's come to my attention that $HTTP_POST_VARS is deprecated and that register_globals is turned off by default in newer versions of php than the one I'm still using, so I've been modifying the earlier script I was playing around with. It would probably also be more useful to keep it in a separate file from the form.

Code: [ Select ]
<?php

$redirectTo = "http://www.yahoo.com";
$to = "you@you.com";
$from = "ContactForm@you.com";
$subject = "Contact Form Submission";
$headers = "From: $from\r\n";

$message = "";
$formFields = array_keys($_POST);

for ($i = 0; $i < sizeof($formFields); $i++)
{
    $theField = strip_tags($formFields[$i]);
    $theValue = strip_tags($_POST[$theField]);
    $message .= $theField;
    $message .= " = ";
    $message .= $theValue;
    $message .= "\n";
}

$success = mail($to, $subject, $message, $headers);

if ($success)
{
    header("Location: " . $redirectTo);
}
else
{
    echo "An error occurred when sending the email.";
}

?>
  1. <?php
  2. $redirectTo = "http://www.yahoo.com";
  3. $to = "you@you.com";
  4. $from = "ContactForm@you.com";
  5. $subject = "Contact Form Submission";
  6. $headers = "From: $from\r\n";
  7. $message = "";
  8. $formFields = array_keys($_POST);
  9. for ($i = 0; $i < sizeof($formFields); $i++)
  10. {
  11.     $theField = strip_tags($formFields[$i]);
  12.     $theValue = strip_tags($_POST[$theField]);
  13.     $message .= $theField;
  14.     $message .= " = ";
  15.     $message .= $theValue;
  16.     $message .= "\n";
  17. }
  18. $success = mail($to, $subject, $message, $headers);
  19. if ($success)
  20. {
  21.     header("Location: " . $redirectTo);
  22. }
  23. else
  24. {
  25.     echo "An error occurred when sending the email.";
  26. }
  27. ?>
Free Programming Resources

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 230 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.