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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts

    form mailer code help

    Please help with this php code. C and C# are really my languages.

    It is intended to take the fields in a web form and place them in an email.

    The other day, two emails were received only containing the line
    "Below is the result of your feedback form. It was submitted on $date at $time.\n\n"
    with no field information.

    Might there be a flaw in this code?


    <?PHP

    // Change "me@this.com" to your email. (you must keep the "" marks)
    $to = "me@this.com";

    // This will be the subject of the Email when it is sent.
    $subject = "Results from your Request Info form";

    // This will be who it is from, usually My site or something like that
    $headers = "From: My Site";


    // redirect? 1=yes 0=no (this is the page you go to after you submit the form.
    // if left on 0 you will see a message then nothing will happen
    // if you select 1 you will see a message then go to the redirect page.)
    $forward = 0;


    // This will be the page you are redirected.
    // (if you keep it 0 you do not need one just delete "yoursite.com"; and leave ""; instead)
    $location = "yoursite.com";


    $date = date ("l, F jS, Y");
    $time = date ("h:i A");

    $msg = "Below is the result of your feedback form. It was submitted on $date at $time.\n\n";

    if ($_SERVER['REQUEST_METHOD'] == "POST") {
    foreach ($_POST as $key => $value) {
    $msg .= ucfirst ($key) ." : ". $value . "\n";
    }
    }
    else {
    foreach ($_GET as $key => $value) {
    $msg .= ucfirst ($key) ." : ". $value . "\n";
    }
    }

    mail($to, $subject, $msg, $headers);
    if ($forward == 1) {
    header ("Location:$location");
    }
    else {
    echo "Thank you for submitting our form. We will get back to you as soon as possible.";
    }

    ?>

  • #2
    Regular Coder
    Join Date
    Nov 2012
    Posts
    115
    Thanks
    7
    Thanked 12 Times in 12 Posts
    There shouldn't be anything wrong with the code as far as I can spot, the empty message you received can only have been from an empty form. Are you catching that on the front end at all?

    Apart from that, if you experience problems related to receiving filled in forms, try the following:

    a) start with commenting out everything from mail() downwards.
    b) echo $msg, see what that looks like. If it shows all of your filled in data, it's all good. If not, continue.
    c) print_r[$_SERVER['POST']; OR print_r[$_SERVER['GET']; - see below
    --> out of curiousity: why check for POST and GET? Surely you define your form at front end as either POST or GET, not randomly or anything? Pick either one and use that as print_r to see what gets through

    If that doesn't lead you anywhere, get back with the results of that and possibly the form too. Good luck!

    Regards,
    Martin

  • Users who have thanked Thyrosis for this post:

    jack0987 (11-27-2012)

  • #3
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks Martin for a very considered response.

    The php code was not done by me. It is on a friends web site and I was helping him.

    On the front end only post is being used. Could we safely remove the else part?

    Prehaps another php mailer may help. Could you suggest one?

  • #4
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    2
    Thanked 1 Time in 1 Post

    how to solve the parse error in php

    following is my php code and the error reads like this parse error in .../mainthead php at line 4 - unexpected T_STRING, expecting ',' or ';'

    <?php
    session_start();
    echo "<!--- Main Head Starts --->;
    \n<link href="assets/jodohStyles.css" rel="stylesheet" type="text/css" /> \n " ;
    \n<link rel="stylesheet" href="assets/style.css"/>
    \n";
    echo "<s";
    echo "tyle type="text/css">
    \n -->
    \n</style>;
    \n
    <div id="page">
    <span id="e1"></span>
    </div>
    \n <d";
    \n " ;
    $row
    $_SESSION
    $_SESSION
    ?>

  • Users who have thanked ramsingh for this post:

    jack0987 (11-27-2012)


  •  

    Posting Permissions

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