电子邮件不通过PHP发送

时间:2013-10-01 00:14:07

标签: php html forms phpmailer

尝试让我网站上的人填写表格并将表格发送到我的电子邮箱。不幸的是,我没有收到消息。这不在本地主机上。我将这个PHP与HTML文件链接在一起。

这是正确的PHP代码吗?

<?php
/* Set e-mail recipient */
$myemail = "myemail@mywebsite.com";

/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], "Enter your name(s)");
$subject = check_input($_POST['subject'], "Enter your age(s)");
$email = check_input($_POST['email']);
$message = check_input($_POST['message'], "Enter your link");
$highschool = check_input($_POST['highschool'], "Enter your high school's website if N/A         write why");

/* 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
Ages: $subject
Link: $message
High School: $highschool
";

/* Send the message using mail() function */
@mail($myemail, $subject, $message);

/* Redirect visitor to the thank you page */
header('Location: thanks.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();
}
?>

0 个答案:

没有答案