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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    New Coder
    Join Date
    Jan 2010
    Posts
    76
    Thanks
    3
    Thanked 0 Times in 0 Posts

    contact form trouble

    im very new to php and im having problems with this contact form. i found a tutorial on youtube for it. im not getting an error when i try it out but im not receiving the email . halp?


    heres the code:
    Code:
    <?php
    
    $name = $_POST["name"];
    $email = $_POST["email"];
    $message = $_POST["message"];
    
    
    mail('email@email.com', 'message', $message, 'From: ' . $name . ' <' . $email . '>');
    header('location: sent.html');
    
    
    ?>
    and heres where im putting everything
    http://switcharoo.agilityhoster.com/contact.html

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Do this, create a new script, name it mailform.php
    Add this code to it and save, upload and test it. Change $to to your email.

    PHP Code:
    <?php
    if ($_POST['submit']) {

    $pullemail $_POST['email'];
    $pullmess $_POST['message'];

    $to "someone@example.com";
    $subject "Test mail";
    $message "$pullmess";
    $from "$pullemail";
    $headers "From: $from";
    mail($to,$subject,$message,$headers);
    echo 
    "Mail Sent.";
    }
    else {
    ?>
    <form method='post' action='mailform.php'>
      Email: <input name='email' type='text' /><br />
      Subject: <input name='subject' type='text' /><br />
      Message:<br />
      <textarea name='message' rows='15' cols='40'>
      </textarea><br />
      <input type='submit' />
      </form>
    <?php
    }
    ?>
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #3
    New Coder
    Join Date
    Jan 2010
    Posts
    76
    Thanks
    3
    Thanked 0 Times in 0 Posts
    i tried out the code but it still wont work
    it wont echo either

  • #4
    New Coder
    Join Date
    Dec 2009
    Posts
    84
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Modified from masterofollies code:
    try this:
    PHP Code:
    <?php
    if ($_POST['submit']) {

    $pullemail $_POST['email'];
    $pullmess $_POST['message'];
    $subject $_POST['subject'];

    $to "someone@example.com";
    $subject "$subject";
    $message "$pullmess";
    $from "$pullemail";
    $headers "From: $from";
    mail($to,$subject,$message,$headers);
    echo 
    "Mail Sent.";
    }
    else {
    ?>
    <form method='post' action=''>
      Email: <input name='email' type='text' /><br />
      Subject: <input name='subject' type='text' /><br />
      Message:<br />
      <textarea name='message' rows='15' cols='40'>
      </textarea><br />
      <input type='submit' />
      </form>
    <?php
    }
    ?>
    Best Regards,

  • #5
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Quote Originally Posted by sir.jones View Post
    Modified from masterofollies code:
    try this:
    PHP Code:
    <?php
    if ($_POST['submit']) {

    $pullemail $_POST['email'];
    $pullmess $_POST['message'];
    $subject $_POST['subject'];

    $to "someone@example.com";
    $subject "$subject";
    $message "$pullmess";
    $from "$pullemail";
    $headers "From: $from";
    mail($to,$subject,$message,$headers);
    echo 
    "Mail Sent.";
    }
    else {
    ?>
    <form method='post' action=''>
      Email: <input name='email' type='text' /><br />
      Subject: <input name='subject' type='text' /><br />
      Message:<br />
      <textarea name='message' rows='15' cols='40'>
      </textarea><br />
      <input type='submit' />
      </form>
    <?php
    }
    ?>
    What was wrong? other than changing the action direction? It'd still load it fine.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #6
    New Coder
    Join Date
    Dec 2009
    Posts
    84
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Nothing wrong at all my friend, i didn't say any wrong before
    Best Regards,

  • #7
    New Coder
    Join Date
    Jan 2010
    Posts
    76
    Thanks
    3
    Thanked 0 Times in 0 Posts
    heres the code you gave me:
    http://switcharoo.agilityhoster.com/contact2.php

    im still not getting an email
    does it just not work with gmail?

  • #8
    Egg
    Egg is offline
    New Coder
    Join Date
    Mar 2008
    Posts
    44
    Thanks
    1
    Thanked 1 Time in 1 Post
    PHP Code:
    <?php
    if ($_POST['submit']) {

    $pullemail $_POST['email'];
    $pullmess $_POST['message'];
    $subject $_POST['subject'];

    $to "someone@example.com";
    $subject "$subject";
    $message "$pullmess";
    $from "$pullemail";
    $headers "From: $from";
    mail($to,$subject,$message,$headers);
    echo 
    "Mail Sent.";
    }
    else {
    ?>
    <form method='post' action=''>
      Email: <input name='email' type='text' /><br />
      Subject: <input name='subject' type='text' /><br />
      Message:<br />
      <textarea name='message' rows='15' cols='40'>
      </textarea><br />
      <input type='submit' name='submit' />
      </form>
    <?php
    }
    ?>

    <input type='submit' name='submit' />


    the php couldn't check whether the form has been submitted or not because the submit button wasn't named. therefore, if you click the submit button, no action is taken.
    Last edited by Egg; 01-19-2010 at 07:24 PM.
    you get out what you put in. lol.

  • #9
    New Coder
    Join Date
    Jan 2010
    Posts
    76
    Thanks
    3
    Thanked 0 Times in 0 Posts
    still no work

  • #10
    New Coder
    Join Date
    Dec 2009
    Posts
    84
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Yeah you'r right Egg, i forgot to put name='submit' before.... oh foolish
    Best Regards,

  • #11
    New Coder
    Join Date
    Jan 2010
    Posts
    76
    Thanks
    3
    Thanked 0 Times in 0 Posts
    could it be the host im using wont allow this to work for some reason?
    other php things ive made worked on here before though, dont see y this wouldnt. im still not getting an email from any of these scripts .

  • #12
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by metathirteen View Post
    im still not getting an email from any of these scripts .
    Are you getting the echo?
    Are you a Help Vampire?

  • #13
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Crap haha forgot the name for it. I get the echo "Mail Sent".
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #14
    New Coder
    Join Date
    Jan 2010
    Posts
    76
    Thanks
    3
    Thanked 0 Times in 0 Posts
    yea i get the echo but i dont get the email.
    i dont understand why

  • #15
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    If you get the echo, then that confirms it's entering the if statement. Are you using a free account with agilityhoster? Their documentation states that free accounts can't send mail. Many other free web hosting accounts also restrict sending mail.

    If you're paying for your account, test the return value for mail(). Something like this:
    PHP Code:
    if ( mail($to,$subject,$message,$headers) )
    {
      echo 
    "Mail accepted for delivery.";
    }
    else
    {
      echo 
    "Mail rejected.";

    Are you a Help Vampire?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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