Contact form will not send email

Hello! I am very new to the world of web development. Especially php. I tried to create a contact form using mail(). Everything looks as though it’s correct, the forms look good and I’m receiving my thank you page after I submit, but I am not actually receiving any emails from it. Can anyone one help. I’ve been looking at this far too many hours.

Here’s my .php

<?php $myemail = "[email protected]" ; $subject = "Self-Defense Message"; $name = check_input($_POST['name']); $phone = check_input($_POST['phone']); $email = check_input($_POST['email']); $message = check_input($_POST['message']); if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("Email address not valid"); } $message = " Subject: $subject Name: $name Phone: $phone Email: $email Message: $message "; mail($myemail, $subject, $message); header('Location: thankyou.html'); function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?>
	<html>
	<body>

	<p>Please correct the following error:</p>
	<strong><?php echo $myError; ?></strong>
	<p>Hit the back button and try again</p>
	
	</body>
	</html>
	<?php
	exit();
}

?>

Add this after the <?

[php]error_reporting(E_ALL);
ini_set(“display_errors”, 1);[/php]

That will show you all your errors, if any.

Also, if you’re not receiving emails, it can be because your local internet provider blocks you sending mail out on port 25 (This is common)

Also check you SMTP settings in you php.ini

Sponsor our Newsletter | Privacy Policy | Terms of Service