0

I've been trying to do a contact form. But my code not working. I'm not receiving any email on my email addresses. i dont know where is the error. Can anybody help me please? Here is my code. Im new on Stackoverflow. So im not sure if i attached the code correctly...

I tried most of the solution on StackOverflow. But none working. I was using Xampp then tried on a server as well. But didnt work anyway. btw, Im a newbie on Web development.

phpmail.php [html form]

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <title>Contact form to email</title>
</head>

<body>

    <form class="email" action="mailer.php" method="post">
  <p>Name:</p>
  <input type="text" name="name" />
  <p>E-mail:</p>
  <input type="text" name="email" />
  <p>Subject:</p>
  <input type="text" name="subject" />
  <p>Message:</p>
  <textarea name="message"></textarea></p>
  <input class="send" type="submit" value="Send">
 </form>

</body>

</html>

mailer.php -----------

<?php
$myemail = "zahedkamal87@gmail.com";

$name = check_input($_POST['name'], "Enter your name");
$subject = check_input($_POST['subject'], "Enter a subject");
$email = check_input($_POST['email']);
$message = check_input($_POST['message'], "Write your message");

if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
$message = "

   Name: $name
   E-mail: $email
   Subject: $subject

   Message: $message

";

mail($myemail, $subject, $message);

header('Location: phpmail.php');
exit();

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();
}
?>
Xahed Kamal
  • 2,203
  • 1
  • 20
  • 41

0 Answers0