Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Contact form

  1. #1
    New Coder
    Join Date
    Oct 2009
    Location
    Walsall, UK
    Posts
    38
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Contact form

    I'm trying to make a contact form that will e-mail me what the user has input. My code all seems to work fine, but then I never receive an e-mail. This is what I've got so far. I am hosting it on a webserver when trying it, and I have put my actual e-mail address in the code, I just took it out so no one would see it on here, in case someone was gonna say that's why it's not working lol.

    contact.php
    Code:
    <form method="POST" action="mailer.php">
       Name<BR>
       <input type="text" name="name" size="19"><br>
       <BR><BR>
       E-Mail<BR>
       <input type="text" name="email" size="19"><br>
       <BR><BR>
       Message<BR>
       <textarea rows="9" name="message" cols="30"></textarea>
       <BR>
       <BR>
       <input type="submit" value="Submit" name="submit">
    </form>
    mailer.php
    PHP Code:
    <?php
    if(isset($_POST['submit'])) {

    $to "me@me.com";
    $subject "Form Tutorial";
    $name_field $_POST['name'];
    $email_field $_POST['email'];
    $message $_POST['message'];
     
    $body "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
     
    echo 
    "Data has been submitted to $to!";
    mail($to$subject$body);

    } else {

    echo 
    "blarg!";

    }
    ?>

  • #2
    met
    met is offline
    Regular Coder
    Join Date
    Oct 2009
    Location
    United Kingdom
    Posts
    728
    Thanks
    4
    Thanked 119 Times in 119 Posts
    code looks fine, looks like its probably a server problem

    you can try

    PHP Code:
    mail($to$subject$body"From: you@yoursite.com"); 
    and setting the from header.

    you can also check if the email is accepted FOR delivery. mail() can't tell you if the email is received however.

    PHP Code:
    if(mail($to$subject$body"From: you@yoursite.com"))
    {
        echo 
    'email was accepted for delivery..';
    } else { 
       echo 
    'somethings not right.';

    Last edited by met; 11-01-2009 at 10:43 AM.

  • #3
    New Coder
    Join Date
    Oct 2009
    Location
    Walsall, UK
    Posts
    38
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Thanks for the reply. The website is for a university assignment, and I'm using the university's web server to host it, so maybe they've disabled outoing e-mail? Ah well, as long as they see the code's fine, I should get the marks for it.


  •  

    Posting Permissions

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