locked
PHP contact email missing the message content RRS feed

  • Question

  • Hi All,

    It has been 10 years since I developed a web site, and I wasn't a developer then. As you can imagine all the tools are different. I have just published the first release of our corporate web site. While there are undoubtedly many opportunities for constructive critizism ;-), I am looking for help on the php script for the contact form. The problem is that the email arrives to the correct address, the subject line correctly reflects the choosen type of inquiry, but the message body is simply the php definition of the message.

    I expect this is something obvious to those of you familiar with php. A missing variable defintion, ' or ;  but I can't find the problem. I also realize that the current contact form is not up to standard from a security perspective. My plan is to get this working and than add email injection protection and re-Captcha scriptlets.

    I know that I can get a free script that will do it all, but since I will need to support this I would prefer to build it up piece by piece so that I understand what I have and the way it works.

    The web site is http://www.etezeract.com

    The php script is listed below. Note: I have suppressed the email address since we know that works. Thanks for your help.

    <?php


    $to = 'xxxx@yyyyyyy.com';
    $subject = $_POST['inquiryOptions'];
    $header = $_POST['emailAddress'];
    $message = 'From: $fullName\nSender e-mail address: $header\nRegarding: $subject\n\nMessage:\n$thoughts\n ';

    if ($header=="") {
     echo "<meta http-equiv=\"refresh\"content=\"0;URL=error.html\">";
     exit;
    }

    $success = mail ($to, $subject, $message, "From: <$header>");

    if ($success){
    echo "<meta http-equiv=\"refresh\"content=\"0;URL=success.html\">";
    }
    else{
    echo "<meta http-equiv=\"refresh\"content=\"0;URL=failure.html\">";
    }

     

     ?>

    Monday, May 28, 2012 12:35 AM

Answers

  • Try using double quotes for $message.  Single quotes just concatenates the contents into a string.  You want the variables inside to be evaluated first: double quotes.
    • Edited by KathyW2 Monday, May 28, 2012 1:34 AM
    • Proposed as answer by Steve Easton Monday, May 28, 2012 2:51 PM
    • Marked as answer by ToniGG Tuesday, May 29, 2012 5:25 PM
    Monday, May 28, 2012 1:30 AM

All replies

  • Try using double quotes for $message.  Single quotes just concatenates the contents into a string.  You want the variables inside to be evaluated first: double quotes.
    • Edited by KathyW2 Monday, May 28, 2012 1:34 AM
    • Proposed as answer by Steve Easton Monday, May 28, 2012 2:51 PM
    • Marked as answer by ToniGG Tuesday, May 29, 2012 5:25 PM
    Monday, May 28, 2012 1:30 AM
  • Hi Kathy,

    So you are saying I shouldchnage the $Message definition to:

    $message = "From: $fullName\nSender e-mail address: $header\nRegarding: $subject\n\nMessage:\n$thoughts\n ";

    I will give it a try. Thanks

    Toni

    Monday, May 28, 2012 1:44 AM
  • Hi Kathy,

    That was it! It works perfectly now. :-)

    So the part I should remember is if I have a line that should have a nested inside portion processed first, I should use double quotes instead of single quotes. Right?

    Monday, May 28, 2012 1:51 AM
  • By the way, this is easy to test: skip actually sending the mail and echo the $message to your screen instead.  When you see what you expect, then worry about actually sending the mail.
    • Edited by KathyW2 Monday, May 28, 2012 2:14 AM typo
    Monday, May 28, 2012 1:51 AM
  • Great idea. Thanks
    Monday, May 28, 2012 2:02 AM