+ Reply to Thread
Results 1 to 3 of 3

Thread: PHP Mailform

  1. #1
    Full Member Steveo31 is on a distinguished road
    Join Date
    Jan 2004

    PHP Mailform

    I have a HTML page with a drop down menu, and a textarea. I am trying to find a way to get the page, once submitted, to upload the variables to an external .php page, and from there it will mail using the mail() function.

    I think this is right:
    PHP Code:
    <form name="form1" method="post" action="mailform.php"
    I'm pretty noobish when it comes to all this, so please, bear with me. Would I have to have some sort of $_POST or somethin?

    If I didn't explain well enough, let me know

  2. #2
    Full Member dzone is on a distinguished road
    Join Date
    Dec 2003

    Well... it should be something like this:

    PHP Code:
    $PG["support_mail"] = "you@domain.net";
    $PG["support_name"] = "Your name";

    $name = trim(safestrip($_POST["name"]));
    $email = trim(safestrip($_POST["email"]));
    $subject = trim(safestrip($_POST["subject"]));
    $message = trim(safestrip($_POST["message"]));
    // ........

    // Check if user has filled in the form completely
    if ( is_email($email) and (!empty($subject)) and (!empty($message)) and (!empty($name)) ) {

       $mail_to         = $PG["support_mail"];
       $mail_to_name    = $PG["support_name"];

       mail ($mail_to, $subject,  $message, "From: ".$name." <".$email.">\r\nTo: ".$mail_to_name." <".$mail_to.">");

    } else {

        if (isset($_POST["submit"]))
            $error_message = "Fill!!!";
            $error_message = "";

    //. . . .. . . .. . . . ... ... .......
       echo $error_message;

    <form action="./" method=post>

            <table border=0>

                <td>Your name:&nbsp;&nbsp;&nbsp;</td>
                <td><input type=text name=name size=40 value=''></td>
                <td>Your e-mail:&nbsp;&nbsp;</td>
                <td><input type=text name=email size=40 value=''></td>
                <td>Please specify:&nbsp;&nbsp;</td>
                <td><input type=text name=subject size=40 value=''></td>
                <td>Your message:<br></td>
                <td><textarea name=message rows=10 cols=40></textarea></td>

            <tr><td colspan=2></td></tr>
            <tr><td colspan=2 align=right><input type=submit name=submit value='Send the message'></td></tr>



    // Check if $email is a quasy-valid e-mail
    function is_email($email) {
    $ret false;
        if ( 
    function_exists("preg_match") && 
    $ret true;
        elseif (
    $ret true;

    // If running with magic_quotes_gpc (get/post/cookie) set
    // in php.ini, we will need to strip slashes from every
    // field we receive from a get/post operation.
    function safestrip($str) {
    get_magic_quotes_gpc()) {
    $str stripslashes($str);
    That is not a complete solution! You'll need to change it so it suits your needs and polish out bugs. Please be attentive and test your script carefully. If you leave a hole there is a big chance that spammers will break in. E.g. never take the destination email from the form field.


  3. #3
    Full Member Steveo31 is on a distinguished road
    Join Date
    Jan 2004
    Ahh some of that makes sense. Some I still need to learn, but eh. I don't have anything else to do with my time

    Thanks for your time Z.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts