我有一个表格,我希望将内容邮寄到一个电子邮件地址,我遇到的问题是,每当我点击提交按钮时,页面只显示原始 PHP 代码并且没有发送电子邮件。我取出了电子邮件地址,但我现在只有一个雅虎帐户用于测试目的。我通过安装了 wordpress 的 WAMP 在本地运行它,并且对 Wordpress 没有任何问题。有什么想法吗?
HTML
<form id="signup" autocomplete="on" method="post" name="contactform" action="http://localhost/contact-form-handler.php">
<div id="prayerRequest"></div><!-- END prayerRequest -->
<textarea class="text" name="prayer" placeholder="* Prayer Request" required=""></textarea><br>
<select name="title" class="dropDown" required="">
<option disabled="disabled" selected="selected">* Title</option>
<option value="Mr">Mr.</option>
<option value="Ms">Ms.</option>
<option value="Mrs">Mrs.</option>
<option value="Dr">Dr.</option>
<option value="Rev">Rev.</option>
<option value="Pastor">Pastor</option>
</select>
<input type="text" class="multiple" name="first" placeholder="* First Name" required="">
<input type="text" class="multiple" name="last" placeholder="* Last Name" required=""><br>
<input type="email" class="full" name="email" placeholder="* Email Address" required=""><br>
<input type="text" class="full" name="address" placeholder="* Street Address 1" required="">
<input type="text" class="full" placeholder="Street Address 2">
<input type="text" class="multiple" name="city" placeholder="* City" required="">
<button type="submit" class="submit">Submit Prayer Request</button>
<p>*Required Field</p>
PHP
<?php
$errors = '';
$myemail = 'myemail@domain.com';//<-----Put Your email address here.
if(empty($_POST['first']) ||
empty($_POST['email']) ||
empty($_POST['prayer']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['first'];
$email_address = $_POST['email'];
$message = $_POST['prayer'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $first \n Email: $email_address \n Message \n $prayer";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Contact form handler</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>