Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 2 of 2

Thread: mailer.php not working.

  1. #1
    1
    posts
    Registered User

    mailer.php not working.

    Hi everyone, Im a self taught noob, who is still learning and have been trying to figure out why my mailer.php file is not working. Well I think that is the problem. Unless Im completely wrong. Whenever I press the submit button for my contact form it gives me a window with two errors.
    The requested URL /contact/mailer.php was not found on this server.
    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
    (Also, this is on the page as well.)
    Apache/2 Server Port 80)
    With this mailer php I found and made subtle changes to it to correspond with the contact form I made, Im trying to have messages sent from a website to my email. If anyone out there knows what my problem is and could steer me in the right direction. I would be extremely appreciative.



    Contact form code:


    <form method="POST" action="mailer.php">
    <label for="Name" id="Name">Name:</label>
    <input type="text" name="Name" />

    <label for="Email" id="Email">Email:</label>
    <input type="text" name="Email" />

    <label for="Tel" id="Tel">Tel:</label>
    <input name="Tel" type="text" maxlength="20" />

    <label for="Message" id="Message">Message:</label>
    <textarea name="Message" rows="20" cols="20"></textarea>
    <input type="submit" name="Submit" value="Submit" class="submit-button" />
    </form>


    PHP code:
    <?php
    if(isset($_POST['submit'])) {
    $to = "myemail@hotmail.com";
    $subject = "Form Tutorial";
    $name_field = $_POST['name'];
    $email_field = $_POST['email'];
    $tel_field = $_POST['tel'];
    $message = $_POST['message'];

    $body = "From: $name_field\n E-Mail: $email_field\n Tel:\n $tel_field\n Message:\n $message";


    echo "Data has been submitted to $to!";
    mail($to, $subject, $body);
    } else {
    echo "blarg!";
    }
    ?>

  2. #2
    Well the error message is saying that it can't even locate the mailer.php file. In your form code, you have action="mailer.php", which means that your mailer.php file should be located in the same folder as the file your form is in. Is that the case?

    Also, are you testing this on your own computer, or do you have an actual web server you're using?

    Just a side note in your mailer.php code, you are going to receive a success message even if the mail() function fails, because the only 'if' conditional you have is checking to see if the form was submitted. You should have your success message in an if statement that makes sure your mail() function was a success. Example:

    Code:
    if(isset($_POST['submit'])) { 
         $to = "myemail@hotmail.com"; 
         $subject = "Form Tutorial"; 
         $name_field = $_POST['name']; 
         $email_field = $_POST['email'];
         $tel_field = $_POST['tel'];
         $message = $_POST['message']; 
         $body = "From: $name_field\n E-Mail: $email_field\n Tel:\n $tel_field\n Message:\n $message"; 
         if ( mail($to, $subject, $body) ){
              echo "Data has been submitted to $to!"; 
        } else { 
              echo "blarg!";
        }
      }
    (The mail function will execute even though it's inside an 'if' conditional, and will return true if it succeeds, and false if it fails - which will tell your 'if' statement which message to display.)
    Proud Montanadian
    You want a toe? I can get you a toe... Hell, I can get you a toe by three o'clock this afternoon, with nail polish.

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