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 9 of 9
  1. #1
    Senior Coder chilipie's Avatar
    Join Date
    Jul 2004
    Location
    Shrewsbury, UK Age: 16
    Posts
    1,117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    mail() form not working

    I have an email form from way back, but in editing it I've somehow managed to break it. Here's what I've got:

    PHP Code:
    <?php

    if(isset($contact))
    {

        if(!empty(
    $_POST['name']) and !empty($_POST['email']) and !empty($_POST['subject']) and !empty($_POST['message']))
        {

            
    mail("ollie@chilipie.co.uk""BM Contact Form: ".$_POST['subject'], $_POST['message'], "From: ".$_POST['name']." <".$_POST['email'].">\r\n") or die("Sorry, but the form isn't working at the moment. Please try again later.");

            
    header("refresh: 0; url=contact.php?form=done");

        } else {

            die(
    header("refresh: 0; url=contact.php?form=error"));

        }
    }

    ?>
    And then below it, in the body of the page:

    Code:
    <?php
    
    		if($_GET['form'] == 'done')
    		{
    			echo "<p>Thank you, your message has been sent successfully. We will endeavour to reply as soon as possible.</p>";
    		}
    
    		if($_GET['form'] == 'error')
    		{
    			echo "<p>Uh-oh! Please check that all fields in the form were filled in and try again.</p>";
    		}
    
    		?>
    
    		<form action="contact.php" method="post">
    
    			<label for="form-name">Name</label>
    			<input type="text" name="name" id="form-name" size="30" />
    
    			<label for="form-email">Email</label>
    			<input type="text" name="email" id="form-email" size="30" />
    
    			<label for="form-subject">Subject</label>
    			<input type="text" name="subject" id="form-subject" size="30" />
    
    			<label for="form-message">Message</label>
    			<textarea name="message" id="form-message" cols="60" rows="10"></textarea>
    
    			<input type="submit" name="contact" />
    
    		</form>
    I'm not getting returned any errors - it just doesn't seem to do anything apart from load contact.php again. It's probably something ridiculously easy to fix, but I'm just lost because of the lack of any error messages.

    Thanks
    Ollie

  • #2
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try this:
    PHP Code:
    <?php

    if(isset($contact))
    {

        if(!empty(
    $_POST['name']) and !empty($_POST['email']) and !empty($_POST['subject']) and !empty($_POST['message']))
        {

            
    mail("ollie@chilipie.co.uk""BM Contact Form: ".$_POST['subject'], $_POST['message'], "From: ".$_POST['name']." <".$_POST['email'].">\r\n") or die("Sorry, but the form isn't working at the moment. Please try again later.");

            
    header("refresh: 0; url=contact.php?form=done");

        } else {

            
    header("refresh: 0; url=contact.php?form=error");

        }
    }

    ?>

  • #3
    Senior Coder chilipie's Avatar
    Join Date
    Jul 2004
    Location
    Shrewsbury, UK Age: 16
    Posts
    1,117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, but it does exactly the same as before - just loads up contact.php.

  • #4
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    nothings triggering $contact i think
    Last edited by ltabdiel; 03-20-2007 at 05:45 PM. Reason: Update

  • #5
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    <?php
    if(isset($_POST['contact'])){

  • #6
    Senior Coder chilipie's Avatar
    Join Date
    Jul 2004
    Location
    Shrewsbury, UK Age: 16
    Posts
    1,117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Heh, it just had to be something that stupid

    Thanks very much guys

  • #7
    Senior Coder chilipie's Avatar
    Join Date
    Jul 2004
    Location
    Shrewsbury, UK Age: 16
    Posts
    1,117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just one more thing...

    What would be the correct way to go about doing this?

    PHP Code:
    $message="$_POST['business']\n$_POST['phone']\n$_POST['description']"
    Basically those three vars with a line break in between.

  • #8
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    $message $_POST['business'] ."\n".$_POST['phone']."\n".$_POST['description']; 
    That's the way I'd do it

  • #9
    Regular Coder goughy000's Avatar
    Join Date
    Nov 2005
    Location
    England
    Posts
    415
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Nightfire View Post
    PHP Code:
    $message $_POST['business'] ."\n".$_POST['phone']."\n".$_POST['description']; 
    That's the way I'd do it
    or \r in it too just incase

    PHP Code:
    $message $_POST['business'] ."\r\n".$_POST['phone']."\r\n".$_POST['description']; 
    Last edited by goughy000; 03-20-2007 at 11:59 PM. Reason: cant spell
    PHP Freelancing!
    ByteForums!
    Scriptlance.comNeed a job done quick? post it on scriptlance! OR! your a programmer? sign up and get paid for these jobs!


  •  

    Posting Permissions

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