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
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP form not sending to all email addresses?

    Hi guys,

    I'm a real beginner here and I could really do with some advice!

    I've created a (very simple) PHP form for my client and have tested it but entering my hotmail e-mail address to send the form to. This seems to work fine. When I enter my client's e-mail address however, the form seems to send, (and re-directs you to the 'thankyou' page) but my client is not recieving any emails?! (not even in their junk mail folder)

    I have posted my code below if it helps. I'm a bit lost here and my client's e-mail provider are not too helpful.

    Thanks in advance guys.


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

    $to "CLIENT_EMAIL_HERE";
    $subject "Contact / Booking Form from booking Website";
    $name $_REQUEST['name'];
    $email_field $_POST['email'];

    $phone $_POST['phone'];
    $comments $_POST['comments'];

    $headers "From: $name via booking website";
     
    $body "From: $name \n\n E-Mail: $email_field\n\n Phone Number: $phone\n\n Message:\n $comments\n";
     
    header"Location: thankyou_contact.html" );
    mail($to$subject$body$headers);

    } else {

    echo 
    "Unexpected error. Please contact your website host";

    }
    ?>
    Last edited by Inigoesdr; 12-28-2011 at 12:43 AM.

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Wrong email put in? maybe their email account doesn't accept mail()?
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,327
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    The mail() function returns a boolean result.

    Therefore you should be testing it like this:
    PHP Code:
    if (mail(<parameters go here>))
       {
       print 
    'Mail sent';
       }
    else
       {
       print 
    'Not sent';
       } 
    Secondly the header/location line should be AFTER the call to mail not before it.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Tags for this Thread

    Posting Permissions

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