Forum Moderators: coopster

Message Too Old, No Replies

Script works on Windows hosting but not Linux!

         

frozenwaste1

8:00 pm on Jan 14, 2008 (gmt 0)

10+ Year Member



Hi,

I'm using the following simple PHP script to write details from a form to a text file - this works fine when hosted on Windows however it doesn't work under Linux hosting, nothing is written to the file! My Linux hosting has PHP5 installed.

Any ideas? Thanks!

<?php
$date = date('H:i, jS F');
@ $fp = fopen("info.txt",'ab');
$details = "\r\n".$date."\t".$_POST["First_Name"]."\t". $_POST["Second_Name"]."\t".$_POST["House_No"]."\t".$_POST["Postcode"]."\t". $_POST["Preferred_Number"]."\t".$_POST["Mobile_Number"]."\t". $_POST["Email"]."\t".$_POST["Contact_Time"]."\t".$_POST["Monthly_Income"]."\t". $_POST["Monthly_Living"]."\t".$_POST["Type_Income"]."\t". $_POST["Total_Owed"]."\t".$_POST["Number_Of_Creditors"]."\t". $_POST["Status_Res"]."\r\n";
fwrite($fp, $details);
fclose($fp);
?>

[edited by: dreamcatcher at 8:50 pm (utc) on Jan. 14, 2008]
[edit reason] Fixed side scroll. [/edit]

jezra

8:33 pm on Jan 14, 2008 (gmt 0)

10+ Year Member



the "@" symbol at the beginning of the line:
@ $fp = fopen("info.txt",'ab');
will disable error reporting for the fopen function, and more than likely, the file info.txt is not being opened on your linux server due to the permissions of the folder that contains your PHP script.

frozenwaste1

9:00 pm on Jan 14, 2008 (gmt 0)

10+ Year Member



Thanks Jezra, it was the permissions! Now working great!

Not having too much luck with migrating to Linux, the following code is not sending the email through, any ideas?!

<?php
$ToEmail = 'example@hotmail.com';
$EmailSubject = 'DM info ';
$mailheader = "From: ".$_POST["Email"]."\n";
$mailheader .= "Reply-To: ".$_POST["Email"]."\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\n";
$MESSAGE_BODY = "First Name: ".$_POST["First_Name"]."\r\n";
$MESSAGE_BODY .= "Second Name: ".$_POST["Second_Name"]."\r\n";
$MESSAGE_BODY .= "House Number/Name: ".$_POST["House_No"]."\r\n";
$MESSAGE_BODY .= "Postcode: ".$_POST["Postcode"]."\r\n";
$MESSAGE_BODY .= "Phone Number: ".$_POST["Preferred_Number"]."\r\n";
$MESSAGE_BODY .= "Mobile Number: ".$_POST["Mobile_Number"]."\r\n";
$MESSAGE_BODY .= "Email Address: ".$_POST["Email"]."\r\n";
$MESSAGE_BODY .= "Contact Time: ".$_POST["Contact_Time"]."\r\n";
$MESSAGE_BODY .= "Monthly Income: ".$_POST["Monthly_Income"]."\r\n";
$MESSAGE_BODY .= "Living Costs: ".$_POST["Monthly_Living"]."\r\n";
$MESSAGE_BODY .= "Income Type: ".$_POST["Type_Income"]."\r\n";
$MESSAGE_BODY .= "Total Debt: ".$_POST["Total_Owed"]."\r\n";
$MESSAGE_BODY .= "Number of Debts: ".$_POST["Number_Of_Creditors"]."\r\n";
$MESSAGE_BODY .= "Residency Status: ".$_POST["Status_Res"]."\r\n";
try{
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader);
}
catch(exception $e){
print "Thank you";
?>

[edited by: jatar_k at 2:24 pm (utc) on Jan. 15, 2008]
[edit reason] examplified email [/edit]

venelin13

9:05 pm on Jan 14, 2008 (gmt 0)

10+ Year Member



First of all, be sure you have the right to use the mail() function at your server. Ask the hosting company about this.

Second. Your email messages are probably treated as spam. You should provide more headers, such as:

//mail headers
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "From: <".$from_email.">\n";
$headers .= "Replay-to: <".$from_email.">\n";
$headers .= "X-Sender: <".$from_email.">\n";
$headers .= "X-Mailer: PHP\n"; // mailer
$headers .= "X-Priority: 3\n"; // normal
$headers .= "Return-Path: <".$from_email.">\n"; // Return path for errors

jezra

10:47 pm on Jan 14, 2008 (gmt 0)

10+ Year Member



To start debugging problems with using the mail() function, it would be helpful to get the message of the exception that is returned by the failed mail function.


try{
mail($ToEmail, $EmailSubject, $MESSAGE_BODY,$mailheader);
print "mail sent";
}
catch(Exception $e){
print "There is an error: ".$e->getMessage();
}