我正在尝试将一个php表单放在wordpress中。由于一些限制,我来到php adn时不是最好的,不幸的是我不能只使用插件。所以我希望你们能帮助我。
截至目前,我可以在静态php页面上发送表单,但是当我将其放入wordpress并测试时,我没有收到电子邮件。这是我的代码
<?php
$action=$_REQUEST['action'];
if ($action==""){ /* display the contact form */
?>
<form class="w2llead" method="post">
<input type="hidden" name="action" value="submit">
<input value="First name" id="sf_first_name" class="w2linput text" name="your-first-name" type="text" placeholder="First name"><br>
<input value="Last name" id="sf_last_name" class="w2linput text" name="your-last-name" type="text" placeholder="Last Name"><br>
<input value="Nonprofit" id="sf_company" class="w2linput text" name="your-company" type="text" placeholder="Company"><br>
<input value="Email Address" id="sf_email" class="w2linput text" name="your-email" type="text" placeholder="Email address"><br>
<br>
<textarea id="sf_description" class="w2linput textarea" name="description" placeholder="Enter your questions here & we’ll get back to you as soon as possible!"></textarea><br>
<div class="w2lsubmit"><input type="submit" name="w2lsubmit" class="w2linput submit" value="Submit"></div>
</form>
<?php
}else{ /* send the submitted data */
$firstname=$_REQUEST['your-first-name'];
$lastname=$_REQUEST['your-last-name'];
$company=$_REQUEST['your-company'];
$email=$_REQUEST['your-email'];
$description=$_REQUEST['description'];
// prepare email body text
$Body = "";
$Body .= "First name: ";
$Body .= $firstname;
$Body .= "\n";
$Body .= "Last name: ";
$Body .= $lastname;
$Body .= "\n";
$Body .= "Company: ";
$Body .= $company;
$Body .= "\n";
$Body .= " Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "description: ";
$Body .= $description;
$Body .= "\n";
if (($firstname=="")||($lastname=="")||($company=="")||($email=="")||($description==""))
{
echo "All fields are required, please fill <a href=\"\">the form</a> again.";
}
else{
$from="From: $firstname<$firstname>\r\nReturn-path: $firstname";
$subject="Still has questions - Nonprofit page";
mail("thebrandonlewis@gmail.com", $subject, $Body, $from);
echo "<h3 style='background:#96E1E2;margin: 0 50px;text-align: center;padding:30px 15px;border-radius: 5px;'>Message sent!</h3>";
}
}
&GT;