July 21, 200818 yr Hi, I've got a problem with mail form on my website. My website is on fasthosts.co.uk server. Looks like they've got some spam protection on server as if someone will put not real email address, I won't receive that email. I would like to leave "email" address as optional, so if someone doesn't want to give me email details or won't fill "email" at all, I'll still receive email. Please help. I checked many forms already... I don't know php so I need solution not tip thats my php file: <?php ini_set('sendmail_from', $email_from); $email_to = "buy@tilesonlinestore.co.uk"; $name =$_POST['name']; $email_from =$_POST['email']; $email_subject = "e-mail from website"; $comments = $_POST['message']; $headers = "From: $email_from .\n"; "Reply-To: $email_from .\n"; /*Email checking*/ if (preg_match('/^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\.-]+\.[a-zA-Z]{2,}$/', $email_from) == false) { echo 'Your email is not valid'; exit; } /*end of checking email*/ /*Now lets build the message of the email with the users name and comments.*/ $message= "Name: ". $name . "\nComments: " . $comments; /*Finally, lets send the email. If the email is sent we will go to a thank you page, if there is an error we will display a brief message.*/ $sent = mail($email_to, $email_subject, $message, $headers, '-f' .$email_from); if ($sent) { header( "Location: http://www.tilesonlinestore.co.uk/sent.htm" ); } else { echo 'There has been an error sending your e-mail. Please try later.'; } ?>
July 22, 200818 yr Use a simple if statement to check whether the email was entered and, if it wasn't, change it to an email of your choice that you know exists: if(empty($email_from)) { $email_from = 'new email'; }
July 22, 200818 yr Author can you point where I should copy that code?? can I leave all the rest like it is??? thank you
July 22, 200818 yr You could try just removing the code that checks for a valid email. <?php ini_set('sendmail_from', $email_from); $email_to = "buy@tilesonlinestore.co.uk"; $name =$_POST['name']; $email_from =$_POST['email']; $email_subject = "e-mail from website"; $comments = $_POST['message']; $headers = "From: $email_from .\n"; "Reply-To: $email_from .\n"; /*Now lets build the message of the email with the users name and comments.*/ $message= "Name: ". $name . "\nComments: " . $comments; /*Finally, lets send the email. If the email is sent we will go to a thank you page, if there is an error we will display a brief message.*/ $sent = mail($email_to, $email_subject, $message, $headers, '-f' .$email_from); if ($sent) { header( "Location: http://www.tilesonlinestore.co.uk/sent.htm" ); } else { echo 'There has been an error sending your e-mail. Please try later.'; } ?> Pat
July 22, 200818 yr Author Pat, I've tried that before. The problem is that if email doesn't really exist, I won't receive any email. That's some spam protection on my stupid server. Also customer won't get any message that email wasn't send.
Create an account or sign in to comment