Hello, I am sort of new to PHP programming. I am very familiar with C++, but i seem to be having some stupid little problems in PHP.

The code I am writing is to validate the information from a form and then email the information in the form to an email account I set up.

first problem: I have a portion of my page where the output is determined by whether or not the email is sent successfully, problem is, both the confirmation and the failure messages show up on the web browser. Somehow, both of my echo statements are making it to the web browser. What did I miss? (and this little bit of php is only a portion of the rest of the php, but this is the only part I have a problem with.)


(some HTML code here)

if ($submit) {            // If submit flag is 1, send mail
                prepvars();
                sendmail();
            
            if ($success) {    // If mail sent successfully, display confirmation
                        echo ("<h3 align=\"center\">Your Submit was successful. We will contact you back as soon as possible. 
                            Thank you.</h3>");            
                            
            
            } else {        // If not successful, tell user
                echo ("<h3 align=\"center\">Your Submit failed. Sorry for the inconvienience. Please Re-Submit, or try again
                        at a later time.</h3>");
                        
            }                // End Submission Failure Warning
        
    }

(more HTML here)

Second problem: Can someone explain the scope of variables a little better to me. My email is being sent to the email account fine, but any portions of the email that would contain variable are empty.
I have a form, then all variables are passed via POST, then in the php script they are processed and then mailed. A lot of the processing happens inside of functions, and then they are mailed by the mail() function. Why are all of my variables blank? Am I getting their scope messed up, such that I, Ideally, i want to get a local variable, but instead it grabs an empty global variable.

Final problem: is there any way to include large portions of HTML within PHP code, without having to escape every single set of quotes? Is there a program that will take code and escape all the quotes for you?

If anyone can help any of my problems, I would really appreciate it.

What's the value of $success?

The syntax of echo does not include ( or ).
echo "This is an echo statement.";

You can have large amounts of HTML (or even small amounts) by turning off PHP processing. Use the ?> tag to do that.

if ( $file_not_found )
  {
  ?>  //Tell PHP not to process this further
  <font size="+2" color="red'>
  Not found, the file is.
  </font>
  <?php //Ok, start processing again
  }

The code above has not been tested, it's merely an example.

Oh yeah, about variable scope:
PHP doesn't treat scope like other languages. If you have a global, you have to declare it global in the function it's global. (Kinda goes against everything you think makes sense, doesn't it?) You can pass variables in via function headings, and they're always in out mode.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.