Now: Tutorial for Web and Software Design > PHP > QA > PHP Content
> PHPFAQ - How can I mail the content of a form? [Bookmark it]
PHPFAQ - How can I mail the content of a form?


Question :

How can I mail the content of a form?

Answer :
<?
/*
You need hidden fields in your form
receipient = received of mailed form content
subject = subject of mailed form content
redirect = page to redirect to
required = fields that must be filled out
i.e. <input type="hidden" name="required" value="name,email,postcode">
*/
$header="From: website@domain.com";
foreach ($HTTP_POST_VARS as $key => $value) 
{
        if($key == "recipient")
        {
                $recipient = $value;
        }elseif($key == "subject")
        {
                $subject = $value;
        }elseif($key == "redirect")
        {
                $redirect = $value;
        }elseif($key == "required")
        {
                $required = $value;
        }else
        {
                $message .= "$key: $value\n";
        }
}
if($required)
{
        $required=split(",",$required);
        foreach($required as $value)
        {
                if($$value=="")
                {
                        echo "You must enter the required information!<P>";
                        echo "Please go back and fill out the form.<BR>";
                        $goback=1;
                }
        }
}
if(!$goback)
{
        $subject = stripslashes($subject);
        $message = stripslashes($message);
        mail($recipient,$subject,$message,$header);
        if($redirect)
        {
                header ("Location: $redirect");
        }
}
?>



[Bookmark][Print] [Close][To Top]
  • Prev Article-PHP:

  • Next Article-PHP:
  • Related Materias
    PHPFAQ - How google is you
    PHPFAQ - Are there any web
    PHPFAQ - How can I accept 
    PHPFAQ - How can I finance
    PHPFAQ - Where can I get P
    PHPFAQ - Where can I host 
    PHPFAQ - Where can I find 
    PHPFAQ - I am trying to cr
    PHPFAQ - Is there a librar
    PHPFAQ - How can I manage 
    Topics
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Graphic Design Tutorial
     

    Coreldraw Tutorial

      Illustrator Tutorial
      3D Graphics Articles
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial&Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial&Articles
     

    XML Style Tutorial

      AJAX Tutorial
      XML Mobile
    Flash Tutorial&Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial&Articles
     

    Linux Tutorial

      Symbian Tutorial
      MacOS Tutorial