Jump to content

Mail Script: Will Windows/linux Server Affect My Coding?


uaintgotthisid
 Share

Recommended Posts

I've got a mail script which works; HereI've got the same script not working; HereThe first is a linux server PHP Infothe second is a windows server PHP info. Would that make a difference to the script?The second difference which is immediately noticable is different versions of PHP (4.4.9 vs 5.2.4). I think this is the more likely of the two to be a problem. Can anyone tell me if (a) the server would make a difference (even if not in this case) and (:) If a simple mail script would differ between versions of PHP?Many thanks in advance people

Link to comment
Share on other sites

It depends what you mean by "simple mail script", but if you're using the PHP built-in mail function and have all of the SMTP settings configured correctly, it will work regardless of the OS.
I'm not entirely sure what I mean myself! I've tried many many many mail scripts. I found it very frustrating indeed. Eventually one worked, not sure why. The code is below, any assistance you could offer would be helpful.
<?php// Read POST request params into global vars $to 	 = 'mye-mail@mail.com';$subject = $_POST['subject'];$from	= $_POST['from'];$name 	 = $_POST['name'];$number  = $_POST['number'];$message = "You have received a message from your website.  Please see below for further details." . "\n\n" . "From: " . $_POST['name'] . " - " . $_POST['from'] . "\n" . "Number: " . $_POST['number'] . "\n\n" . "Message: " . $_POST['message'];$headers = "From: $from";if (is_uploaded_file($fileatt)) {  // Read the file to be attached ('rb' = read binary)  $file = fopen($fileatt,'rb');  $data = fread($file,filesize($fileatt));  fclose($file);  // Generate a boundary string  $semi_rand = md5(time());  $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";    // Add the headers for a file attachment  $headers .= "\nMIME-Version: 1.0\n" .			  "Content-Type: multipart/mixed;\n" .			  " boundary=\"{$mime_boundary}\"";  // Add a multipart boundary above the plain message  $message = "This is a multi-part message in MIME format.\n\n" .			 "--{$mime_boundary}\n" .			 "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .			 "Content-Transfer-Encoding: 7bit\n\n" .			 $message . "\n\n";  // Base64 encode the file data  $data = chunk_split(base64_encode($data));  // Add file attachment to the message  $message .= "--{$mime_boundary}\n" .			  "Content-Type: {$fileatt_type};\n" .			  " name=\"{$fileatt_name}\"\n" .			  //"Content-Disposition: attachment;\n" .			  //" filename=\"{$fileatt_name}\"\n" .			  "Content-Transfer-Encoding: base64\n\n" .			  $data . "\n\n" .			  "--{$mime_boundary}--\n";}// Send the message$ok = @mail($to, $subject, $message, $headers);if ($ok) {  echo "Mail Successful code";} else {  echo "Mail unsucessful code";}?>

Link to comment
Share on other sites

That looks fine to me, that uses the built-in mail function to send a mail with an optional attachment. If that's not working, I would remove the @ symbol near the end before mail, using that operator will cause any errors with the mail function to be ignored. If it's not working, you would probably want to see what the error says. That mail script is susceptible to a certain type of email attack, but other than that it looks fine.

Link to comment
Share on other sites

I've removed the @ symbol as suggested earlier. The mail script is still working on my normal server, but not on the client server. I've tried to add in the other injections stuff, although I'm not sure that's working yet. The main thing I want to try is to get the thing working first. Any ideas?

Link to comment
Share on other sites

Make sure errors are enabled on the server. If the script is automated, you can write PHP errors to a log file to check there. In terms of settings, these are the settings in php.ini used by the mail functions:http://www.php.net/manual/en/mail.configuration.phpThe SMTP or sendmail options need to be set correctly in order for mail to work. If everything looks fine and PHP isn't reporting errors, check the mail server software for errors. It should be keeping a log of mail traffic and if there's a delivery problem it should log that somewhere.Also, test with a barebones mail script like on the examples on the mail reference page on php.net:http://www.php.net/manual/en/function.mail.phpJust test with hard-coded information to rule out anything else the script is doing.

Link to comment
Share on other sites

  • 1 month later...
It looks like there are differences between a WAMP and LAMP installation
Maybe one of the machines doesn't have a mail server installed?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...