Results 1 to 11 of 11

Thread: PHP Mail Form not working

  1. #1

    PHP Mail Form not working

    Hi! I got this error msg when I tried the PHP Mail Form:

    Notice: Undefined variable: submit in /vservers/furries01/htdocs/mail.php on line 16

    Can someone help?? Do I miss anything? Line 16 is if($submit).

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/URL]">
    <html xmlns="[URL]http://www.w3.org/1999/xhtml[/URL]">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <?
    //------------------------------------------------
    // File: 'phpmail.php'
    // Func: using mail();
    //------------------------------------------------
    $Subject "Info";                         
    $toEmail "[EMAIL="oli99via@yahoo.com"]oli99via@yahoo.com[/EMAIL]";       
    if(
    $submit)
    {
    mail($fromEmail$Subject$nMessage."\nFrom: ".$fromName."<".$fromEmail.">");
    }
    ?>
    </head>
    <body>
    <form id="form1" name="form1" method="post" action="<? echo($PHP_SELF?>">
      <p>Your Email
        <input type="text" name="fromEmail" id="fromEmail" size="25" />
      </p>
      <p>Your Name
        <input type="text" name="fromName" id="fromName" size="25" />
    </p>
      <p>Your Message
        <textarea name="nMessage" id="nMessage" cols="45" rows="5"></textarea>
      </p>
      <p>
        <input type="submit" name="submit" id="submit" value="Submit" />
      </p>
    </form>
    </body>
    </html>

  2. #2
    yes... like the code says... Undefined variable... $submit is set to nothing. You need to set it above the if statement... in this case it'd be
    PHP Code:
    $submit $_POST['submit']; 
    also... just a heads up but your form is also going to return blank values... for the same reason, you haven't defined the other variables either.
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  3. #3
    $submit = $_POST['submit'];
    $fromName = $_POST['fromName'];
    $Subject = $_POST['Subject'];
    $nMessage = $_POST['nMessage'];
    $fromEmail = $_POST['fromEmail'];

    I defined all the variables as above and put them before the if statement, but for some reasons I still get the following errors:

    Notice: Undefined index: submit in /vservers/furries01/htdocs/mail.php on line 16

    Notice: Undefined index: fromName in /vservers/furries01/htdocs/mail.php on line 17

    Notice: Undefined index: Subject in /vservers/furries01/htdocs/mail.php on line 18

    Notice: Undefined index: nMessage in /vservers/furries01/htdocs/mail.php on line 19

    Notice: Undefined index: fromEmail in /vservers/furries01/htdocs/mail.php on line 20


    Any idea why? Thank you!

  4. #4
    It's not an error, it's a notice. They're different things... error means it doesn't work... notice is more of a nag, but more times than not it doesn't affect the function of your script. You just need to turn notices off... it should be working tho.
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  5. #5
    Well, notice means it doesn't work too! I tried my form and when I hit the submit button, I got HTTP 404. Weird. How come no one has this problem but me? How do you turn the notices off??

  6. #6
    no... notice doesn't mean it doesn't work . and you get the 404 cause this is wrong:
    PHP Code:
    action="<? echo($PHP_SELF?>"
    it should be

    PHP Code:
    action="<? echo $_SERVER['PHP_SELF']; ?>"
    as for the notices
    http://us2.php.net/error-reporting
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  7. #7
    Sim, thanks for replying. Unfortunately, echo $_SERVER['PHP_SELF']; doesn't help.

    I kinda want to give it up now until I pick up PHP. I don't have to have this mail form. The reason I gave it a try because I was just curios about this mail form. But like I said, I am learning. I don't have to have this mail form on my website although it would be nice to have it. So thanks again for helping!! It's very much appreciated.

    Keep up the good work.

  8. #8
    well... if I'm looking at this correctly...
    PHP Code:
    <?
    //------------------------------------------------
    // File: 'phpmail.php'
    // Func: using mail();
    //------------------------------------------------
    $Subject "Info";                         
    $toEmail "[email="oli99via@yahoo.com"]oli99via@yahoo.com[/email]";       
    if(
    $submit)
    {
    mail($fromEmail$Subject$nMessage."\nFrom: ".$fromName."<".$fromEmail.">");
    }
    ?>
    won't send to you anyway, there's a couple things you want to try to do when you're using the mail function (or any other function really). But you want to try and limit it to just variables. Something like this:
    Code:
    $nMessage."\nFrom: ".$fromName."<".$fromEmail.">"
    just makes it look sloppy. Also, take a look at the mail() function again on php.net

    here... I'll help you out here a lot, this is what your basic form should look like
    PHP Code:
    <?php
        
    //------------------------------------------------
        // File: 'phpmail.php'
        // Func: using mail();
        //------------------------------------------------
        
    $submit $_POST['submit'];

        if( !empty(
    $submit) && isset($submit) )
        {
            
    $to 'oli99via@yahoo.com';   
            
    $subject 'Info';

            
    $fromEmail $_POST['fromEmail'];
            
    $fromName $_POST['fromName'];
            
    $nMessage $_POST['nMessage'];

            
    $from "$fromName <$fromEmail>";

            
    $headers "From: $from\r\n";
            
    $headers .= "Reply-to: $fromEmail\r\n";
        
            
    mail$to$subject$nMessage$headers );
        }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[url]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/url]">
    <html xmlns="[url]http://www.w3.org/1999/xhtml[/url]">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>

    </head>
    <body>
    <form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <label>Your Email
            <input type="text" name="fromEmail" id="fromEmail" size="25" />
        </label><br/>
        <label>Your Name
            <input type="text" name="fromName" id="fromName" size="25" />
        </label><br/>
        <label>Your Message
            <textarea name="nMessage" id="nMessage" cols="45" rows="5"></textarea>
        </label><br/>
        <input type="submit" name="submit" id="submit" value="Submit" />
    </form>
    </body>
    </html>
    Note that this form is 100% unsecured and before you plan on using it you should look up ways to help prevent injection, XSS, and other malicious crap that can be done w/ forms.
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  9. #9
    Still get Notice: Undefined index: submit in ... *Sigh.

  10. #10
    did you look at the link i sent about the error reporting?... in the first line of the script just put
    PHP Code:
    error_reporting(E_ALL E_NOTICE); 
    your servers php.ini should be set that way anyway, it's odd for it not to be, that's PHP's default
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  11. #11
    simplistik's code works fine... Maybe you might want to post the code you have and maybe post the URL where we can see...
    CyanBlue / Jason Je / Flash Developer
    http://CyanBlue.FlashVacuum.com
    http://www.FlashVacuum.com

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
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012