uaintgotthisid Posted March 11, 2009 Share Posted March 11, 2009 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 More sharing options...
justsomeguy Posted March 11, 2009 Share Posted March 11, 2009 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. Link to comment Share on other sites More sharing options...
uaintgotthisid Posted March 11, 2009 Author Share Posted March 11, 2009 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 More sharing options...
justsomeguy Posted March 11, 2009 Share Posted March 11, 2009 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 More sharing options...
uaintgotthisid Posted March 19, 2009 Author Share Posted March 19, 2009 Cheers for your help. I use the form to call this mail script but it has the e-mail address for the "to" already filled in. Does this still mean it's subseptible to attacks? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 19, 2009 Share Posted March 19, 2009 It's susceptible only because it uses data from the form in the mail headers, specifically the from address. There's a discussion about that here:http://w3schools.invisionzone.com/index.php?showtopic=16773 Link to comment Share on other sites More sharing options...
uaintgotthisid Posted March 24, 2009 Author Share Posted March 24, 2009 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 More sharing options...
justsomeguy Posted March 24, 2009 Share Posted March 24, 2009 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 More sharing options...
uaintgotthisid Posted April 26, 2009 Author Share Posted April 26, 2009 It looks like there are differences between a WAMP and LAMP installation Link to comment Share on other sites More sharing options...
Synook Posted April 27, 2009 Share Posted April 27, 2009 It looks like there are differences between a WAMP and LAMP installationMaybe one of the machines doesn't have a mail server installed? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.