WebFaction
Community site: login faq
0
1

I have a bunch of websites all on the same server that are using the same php script to send emails from form submission. What is the problem with creating a folder in my home directory, outside of my webapps folder, and putting the mail script there?

asked 26 Oct '11, 22:14

LarryLampco
313
accept rate: 0%

edited 26 Oct '11, 22:15


Nothing should prevent that from working. Even though the script is outside of the webroot, you should be able to call it via php through it's full path. Are you encountering issues with this type of approach?

permanent link

answered 26 Oct '11, 23:26

ryans ♦♦
5.0k103860
accept rate: 43%

Yes, the form acts like it submits but I do not get any emails and the location header from the script is not sent because I do not get the thank you page.

(27 Oct '11, 00:15) LarryLampco

How are you calling the mailer script from the php file under your webroot, and what credentials (minus password) are you using in your smtp configuration?

(27 Oct '11, 00:22) ryans ♦♦

Mailer script is being called via the action attribute. I am using the Swift Library to send the mail. smtp.webfaction.com port 25. The mail script works fine inside webroot. The path for the mail script in the action attribute is ../../resources/send_mail1.php.

(27 Oct '11, 00:33) LarryLampco

I'm not sure what you mean by the "Action" attribute; normally, that would interpret the argument as a URL path, not a filesystem path. If that's the case, you're pointing to a nonexistent URL if you tell that to navigate outside of the webroot.

If you want to place the script elsewhere, you should execute it in a subprocess directly using the /usr/local/bin/php on the system. Any method that relies on calling the script through Apache won't work (by definition) outside of the webroot.

(27 Oct '11, 00:46) ryans ♦♦

The form script is being called via the "action" attribute of the form tag. Thanks for your help! I will do some research on executing it in a subprocess.

(27 Oct '11, 00:50) LarryLampco

Ah, yeah, that definitely seems like the problem. Try using something like this in PHP:

system("/usr/local/bin/php /home/USERNAME/my_mailer.php");

That effectively executes the "php" program to run the mailer script in a subprocess. You could have your "Action" attribute call a do_send_mail.php page, which, in turn, executes the above in a subprocess.

Hope that helps!

(27 Oct '11, 00:55) ryans ♦♦

One last question. The php script I am using is including a file that is outside of webroot. Here is the require_once statement in my script: require_once '../../resources/lib/swift_required.php'; You said "Any method that relies on calling the script through Apache won't work (by definition) outside of the webroot." Does this require once_function not rely on Apache?

(27 Oct '11, 00:55) LarryLampco

Correct - require_once should not rely on apache. Effectively, php just interprets and processes the require_once statement, which imports an external php file.

The reason is confusing (and confusing, it is, indeed) is that there is a difference between paths in "URL Space" and "Filesystem Space".

When a browser initiates a request, that calls a URL. This path is a URL-space path. It ultimately becomes something like http://www.domain.dom/foo/bar.php. Often, in your PHP, you are generating URLs and the framework will automatically turn some relative paths into URLs as well. In general, any paths that will get sent to the user's browser will be URL-space paths.

Filesystem-space paths are different; they never leave the webserver, and are not generated by php output or HTML pages. They are "internal" to the system. Therefore, the require_once statement or calling a path in a system() call (a subprocess) will use a filesystem-path.

Frameworks also sometimes define special methods to turn URL Paths into Filesystem paths. For example, if you ever see some rewrite rules in a .htaccess file which append paths onto an index.php file, then you are looking at a system for mapping URL Paths onto some file on the physical filesystem.

Therefore, the relationship between URL-space and Filesystem-space is an important one, and in some cases, the major differences between different web frameworks includes how they handle such conversions.

(27 Oct '11, 01:11) ryans ♦♦
showing 5 of 8 show 3 more comments
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×70
×25

question asked: 26 Oct '11, 22:14

question was seen: 3,252 times

last updated: 27 Oct '11, 01:12

                              
WEBFACTION
REACH US
SUPPORT
LEGAL
© COPYRIGHT 2003-2020 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM