1

When I try using include to add php code to a sendmail script called from a form it doesn't pull in the code like I would expect.

Is there another method I should use to add code to a script?

Thanks in advance.

1
  • 2
    if(accept_rate == 0) response_rate = 0; Commented Mar 7, 2011 at 2:31

2 Answers 2

1

Besides

include( 'myFile.php' );

you might use

require( 'myFile.php' );

which fails, if the respective file doesn't exist.

In general, I'd propose to use

require_once( 'myFile.php' );

which - even if executed several times - loads the file only once.

Beside these function, give

file_get_contents( 'file.ext' );

a try or maybe

file_get_contents( dirname( __FILE__ ) . '/../file.ext' );

to read relative to the directory of the calling script.

Finally, note that

eval( $someStringVariable );

may be used to make PHP evaluate $someStringVariable as if its contents is PHP source-code.

If all this isn't what you are in search for, please provide more details.

Sign up to request clarification or add additional context in comments.

Comments

0

Before you include the form-handling php code, include a file with ONLY the following:

<?php
print '<pre>FILE WAS INCLUDED</pre>';
?>

Name it "test_php_file.php". Then at the top of the file that the form posts to, include the above file like so:

<?php include('test_php_file.php'); ?>
<html>
<head>
...
</html>

If your page prints out "FILE WAS INCLUDED" at the top of the page (assuming Apache parsed it first), then you are good to include the real php code in the same manner. Remember that file inclusion works similarly to inline image rendering: the string you pass include is the filename as well as the relative path. Keep the php file within the same directory as the file that includes it so that way you don't have to worry about the path:

forms/
    form.html
    test_php_file.php
    real_php_file.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.