我有一個不發送郵件的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我不是。 :) –