我有一个不发送邮件的PHP邮件表单。该脚本像用户应该那样运行;把他们带到“谢谢你!”页面,但邮件永远不会到它应该去的电子邮件地址。我该如何解决这个问题?我试图通过其他线程解决它在stackoverflow,但我的问题是独特的。PHP邮件表单不发送邮件
PHP
<?php
/* Set e-mail recipient */
$myemail = "[email protected]";
/* Check all form inputs using check_input function */
$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 e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
$message = "
Name: $name
E-mail: $email
Subject: $subject
Message:
$message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: http://www.thewebsite.com/thankyou.html');
exit();
/* Functions we used */
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();
}
?>
你使用wordpress吗? –
那么'john.doe @ example.com'不是一个有效的电子邮件吗? https://regex101.com/r/OvRqyw/1 – Andreas
@Sreejith学士学位,不,我使用这个我建立自己的网站。 HTML,CSS和JavaScript我很熟悉,但PHP我不是。 :) –