我正在尝试使用带有 PHP 的表单发送电子邮件。
我的PHP代码:
<?php
$name = trim(strip_tags(stripslashes($_POST['name'])));
$email = trim(strip_tags(stripslashes($_POST['email'])));
$subject = trim(strip_tags(stripslashes($_POST['subject'])));
$message = trim(strip_tags(stripslashes($_POST['message'])));
$successful = "Message was sent";
$failure = "Message was not sent";
$header = "From: $email\r\n";
$validEmail = filter_var($email, FILTER_VALIDATE_EMAIL);
if ($name <> "" && $email <> "" && $subject <> "" && $message <> "") {
if ($validEmail) {
mail ("myemail@em.com", $subject, $message, $header);
header("Location: emailsent.php?message=$successful");
}
else {
header("Location: emailnotsent.php?message=$failure");
}
}
?>
我的 HTML:
<form method="post" name="contact" action="sendMail.php">
<label for="author">Name:</label> <input type="text" id="author" name="name" class="required input_field" />
<div class="cleaner h10"></div>
<label for="email">Email:</label> <input type="text" class="validate-email required input_field" name="email" id="email" />
<div class="cleaner h10"></div>
<label for="subject">Subject:</label> <input type="text" class="validate-subject required input_field" name="subject" id="subject"/>
<div class="cleaner h10"></div>
<label for="text">Message:</label> <textarea id="text" name="text" rows="0" cols="0" name="message" class="required"></textarea>
<div class="cleaner h10"></div>
<input type="submit" value="Send" id="submit" name="submit" class="submit_btn float_r" />
<input type="reset" value="Reset" id="reset" name="reset" class="submit_btn float_l" />
</form>
当我提交表单时,我收到以下错误:
致命错误:调用未定义函数:第 13 行 /home/web/i/interfaithmedical.com/htdocs/PagesByZ/sendMail.php 中的 filter_var()