Ive had my website up and running for many years now without any real issues until last year when my hosts Streamline decided to switch off register_globals with no prior warning. After help from you guys i managed to migrate the code to PHP5 and get it working again.
Well now something similar is happening i think (i.e that Streamline have changed server side settings without any warning).
There has only been one occurance of the error im aware of (reported to me by a user), I can not recreate the error myself in testing.
I got an email from a user saying they had experienced the following error when using my site to send an email to us.
"error 500 Internal server error when running the "sendeail.php""
sendeail.php is my script containing my mail()
my website and the form he was using is here:
http://www.winyateshc.co.uk/prescriptions2.php?pageid=2
here is the content of sendeail.php
<?php
$isformvalid = true;
$isspamfree = true;
if((!$_POST['visitormail'] == "" && (!strstr($_POST['visitormail'],"@") || !strstr($_POST['visitormail'],"."))) || (empty($_POST['visitor'])) || (empty($_POST['visitormail'])) || (empty($_POST['notes'])) || (empty($_POST['dobday']) || empty($_POST['dobmonth']) || empty($_POST['dobyear'])) ) {
$isformvalid = false;
include('emailerror.php');
/* calls emailerror page insert if any field is invalid */
}
else {
include('isspam.php'); }
/* spam filters - calls spam filter check before proceeding any further */
if($isspamfree == true) {
$todayis = date("l, F j, Y, g:i a") ;
$subject = "Repeat prescription request";
$from = $_POST[visitormail];
$notes = stripcslashes($_POST['notes']);
$dob = $_POST['dobday'].$_POST['dobmonth'].$_POST['dobyear'];
/* phpinfo(INFO_VARIABLES); displays all variable values test if needed*/
$message = "$todayis [EST] \n
From: $_POST[visitor] ($_POST[visitormail])\n
DOB: $dob \n
Medication: $notes \n
Additional Info : IP = $_POST[ip] \n
Browser Info: $_POST[httpagent] \n
Referral : $_POST[httpref] \n
";
}
if(($isformvalid == true) && ($isspamfree == true)) {
"From: $_POST[from]\r\n";
mail("prescriptions@winyateshc.co.uk", $subject, $message, $from, "-froot@winyateshc.co.uk");
include('formcorrect.php');
/* calls form correct page insert */
}
?>
Now I've contacted Streamline who seem less than interested, but did after some prodding later replied with the following
"Thank you for your query
Our engineers have confirmed that in most of the cases with email not being sent they are seeing this issue is being caused by the server rules for these scripts being more stringently enforced and the –f command not being used within the script as is required on our servers.
All outbound email must be routed through our outgoing email servers or it will not be delivered, it is not possible to send email from a script directly to a third party SMTP server.
In order for the script to work, you need to specify, via a fifth -f parameter, the domain from which the mail is being sent. The PHP component uses SMTP, and all Streamline.net' SMTP servers have filters which ensure that the data returned by either the first or fifth mail parameter relates to one of your domains hosted by Streamline.net. The final part of the script thanks the visitor for the message. This is done by sending an HTTP header back to the visitor's browser telling it to load a file called thankyou.html from your domain. The /header/function allows you to send any HTTP header back to the browser.
Here is a sample of a working PHP mail script (you will need to fill in details):
$from = "thefromemailaddress@domain";
mail("recipient@", "Test mail from PHP mail","This is a test PHP Email","From: $from", "-f$from" );
print "Mail sent";
?>
This script if edited properly will prove the working of the PHP mail() function on our servers.
Failing this please contact a Professional PHP developer."
Looking at my code I DO specify the -f parameter and I am sending from my own domain email?
mail("prescriptions@winyateshc.co.uk", $subject, $message, $from, "-froot@winyateshc.co.uk");
Can i do away with the visitors email altogether and just set $from to my domain email or should i somehow add $replyto in and assign the visitor email to that instead? (I dont need to know the visitors email, I only put it on the form because I thought the mail() demanded a $from - i didnt know i could set it to my own domain email at the time)
Lastly, in the example code Streamline sent it refers to
Print "mail sent"
and how it redirects their browser to a thankyou page.
I do not want to send a confirmation email to people using the form (we do not want people reply to the confirmation with queries or enter in to dialogue, I just want to offer the service allowing them to submit their request. Ive written an include(thankyou.php) which will only be display if they mail() completes sucessfully eliminating the need for a confimation email or browser redirects being sent back to the sender)