Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Help - input used to go to sendmail now to file

Posted by technodiva (technodiva), 9 November 2004
I have the following sendmail script..it works...however Inow when the user fills out the form in flash, I want sendmail.php, to write the person's email to a .txt file since my email is getting filtred...

Here is the sendmail script:

<?
if(!empty($HTTP_POST_VARS['sender_mail']) || !empty($HTTP_POST_VARS['sender_message']) || !empty($HTTP_POST_VARS['sender_subject']) || !empty($HTTP_POST_VARS['sender_name']))
{
     $to = "me@me.com";
     $subject = "Submitted from the SCL website / SCL mailing List";
     $body = stripslashes($HTTP_POST_VARS['sender_message']);
     $body .= "I would like to be added to the monthly SCL mailing list for legal tips and tricks. Please add my email address to your list.";
     $body .= " My email address is: " . $HTTP_POST_VARS['sender_name'] . " " . $HTTP_POST_VARS['sender_mail']  . "";
     $header = "From: " . $HTTP_POST_VARS['sender_name'] . " <" . $HTTP_POST_VARS['sender_mail'] . ">\n";
     $header .= "Reply-To: " . $HTTP_POST_VARS['sender_name'] . " <" . $HTTP_POST_VARS['sender_mail'] . ">\n";
     $header .= "X-Mailer: PHP/" . phpversion() . "\n";
     $header .= "X-Priority: 1";
     if(@mail($to, $subject, $body, $header))
     {
           echo "output=sent";
     } else {
           echo "output=error";
     }
} else {
     echo "output=error";
}
?>


Here is the script I have written which doesn't seem to be working...using the post variable from the previous script (this is the variable that contains the user's email address?) (I have  inherited this project...)

<?php
<?
$file = "/_private/form_results.txt"; // Name & location of the text file
$fp = fopen ("$file","a"); // open the file and set it to write at end.


fputs($fp, " $HTTP_POST_VARS['sender_mail']"
"); // write to the text file
fclose($fp); // close the textfile
?>

Posted by admin (Graham Ellis), 10 November 2004
on 11/09/04 at 19:38:46, technodiva wrote:
.... which doesn't seem to be working...


What actually happens?   Do you get an error message, and if so, what is it? Does the whole thing appear to work but nothing appear in the file?

I'm really guessing here but the folllowing strike me about the piece of code at the end ...

a) you seem to be writing to a file at an absolute path where I suspect you don't have permission to write.  You might want to be writing "../_private .....   in place of "/_private ....   (notice the extra 2 dots)

b) You appear to have one too many double quotes on the end of your fputs.  But that could just be a slipup in copying and pasting your script here.

I am also wonding if your web server has write access to the log file. As a regular user, you might have created the file and be able to write to it yourself, but the web server (running under a different user account) may not have write permissisons to it, or access to the directory containing it.

If it was one of these, please follow up to let us know. Otherwise, please give us a bit more about how it fails - error messages, whether the output file exists/is created and if so what happens to it when you run the script, etc.

Posted by technodiva (technodiva), 10 November 2004
Thanks for your suggestions Graham...unfortunately none of your suggestions worked...

There is no error message...the script seems to execute...however nothing is written to the file. I believe we have access to the file, since it is the same one we use to write to from our html pages.

Should I try to test the script locally? I am not really familiar with PhP, but was reading somewhere about local testing..this way I can at least see if the script runs, then address the issue of file access.

Do you have suggestions about what to use for local testing?

Thanks again...Gayle

Posted by admin (Graham Ellis), 10 November 2004
a) If you have PHP locally for testing, I would ceratinly suggest that you type in
        php sendmail.php
to see what it says.

b) Have you looked in your web server's log file - error messages whould be written there

c) How are you so sure that your web server has access to write the file?  It's usual for developments working on the HTML of a web site to do so under one user account, but for the web server itself to use another.   Tricky one this to explain in a few words if it's a new concept to you - what operating system does the server run?

d) as a test. comment out your file opening statements and turn the fputs into a print ... then see what you get on the browser.  If it doesn't work you have a fundamental problem and perhaps the script isn't even being run.  If it does work then you can gradually put stuff back in and isolate the problem down to one or two statements.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho