hello friends, the following PHP script on my website has stopped working without me editing it :
<?php if(isset($_POST['email'])) {// CHANGE THE TWO LINES BELOW $email_to = "[email protected]"; $email_subject = "enquiry"; function died($error) { // your error code can go here echo "Sorry, but errors were found in the form you submitted.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['full_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['full_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= ‘The Email Address you entered does not appear to be valid.
’;
}
$string_exp = “/^[A-Za-z .’-]+$/”;
if(!preg_match($string_exp,$first_name)) {
$error_message .= ‘The Full Name you entered does not appear to be valid.
’;
}
if(strlen($comments) < 2) {
$error_message .= ‘The Comments you entered do not appear to be valid.’;
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = “Form details below.\n\n”;function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Full Name: ".clean_string($first_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
‘X-Mailer: PHP/’ . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>Thank you for contacting us, we will be in touch soon.
<?php } die(); ?>
which was working with the following form:
Full Name * Email Address * Telephone Number Message *
Now, I have tried the following test script found here (http://myphpform.com/php-form-not-working.php) and it does not work :
<?php $from = "[email protected]"; $headers = "From:" . $from; echo mail ("[email protected]" ,"testmailfunction" , "Oj",$headers); ?>
so I have then contacted my Host which replied as follows:
when you send emails by scripts and it is that our SMTP server requires authentication in order to send emails out. By using one of the emails that exist in the control panel as a sender/"from" header, you will be able to authenticate yourself and the SMTP server will send without problems.
and provided this script, which works:
<? $from = "From: You "; $to = "[email protected]"; $subject = "Hi2! "; $body = "TEST";if(mail($to,$subject,$body,$from)) echo “MAIL - OK”;
else echo “MAIL FAILED”;
?>
so can someone help me fix the code in the first quote I posted based on this last working one ?
A few things maybe worth a mention:
- previously, about a few weeks back, this form (first two quotes) was working perfectly as I’ve posted it and sending emails to my hotmail account without a hitch…
- in the quotes "[email protected]" is actually the domain email I have with the host
thanks to anyone kind enough to help out…