Hi I´m new to PHP so hopefully someone can help me. I have read various topics about this but don´t seem to find a solution. I have a PHP code that I found that I have connected to my HTML contact form. This code worked on my other site that had another web host and had not SSL certificate. On my old site I received the email but I don´t on the new site. I think I need to add my web hosts IMAP and port to this PHP but I cant figure out how.
<?php if (isset($_POST['email'])) {
$email_to = "myemail@something.com";
$email_subject = "Contact form";
function died($error) {
echo "Message not valid.<br /><br />";
echo $error."<br /><br />";
echo "Message not valid.<br /><br />";
die();
}
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['comments'])) {
died('Message not valid');
}
$name = $_POST['name'];
$email_from = $_POST['email'];
$comments = $_POST['comments'];
$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 .= 'Message not valid.<br />';}if(strlen($comments) < 2) {
$error_message .= 'Message not valid.<br />';}if(strlen($error_message) > 0) {
died($error_message);}$email_message = "Contact form.\n\n<br /><br />";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."\n<br />";
$email_message .= "Email: ".clean_string($email_from)."\n<br />";
$email_message .= "Comments: ".clean_string($comments)."\n<br />";$headers = 'Content-type: text/html; charset=UTF-8' . "\r\n".'From: '.$email_from."\r\n".'Reply-To: '.$email_from."\r\n" .'X-Mailer: PHP/' . phpversion();@mail($email_to, $email_subject, $email_message, $headers); ?> We will be in touch with you very soon.
<?php
}
die();
?>