我试图让我的电子邮件表单正常工作,但似乎有些事情悬而未决。它根本不发送电子邮件!
作为参考,这使用Wordpress,这是代码:
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="#" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Your name:<br>
<input name="username" type="text" value="" size="30"/><br>
Department:<br>
<select id="department" class="form-control-footer">
<option value="Email_0">Sales</option>
<option value="Email_1">Support</option>
<option value="Email_2">Website Feedback</option>
<option value="Email_3">Other</option>
</select><br>
Email Subject<br>
<input name="emailsubject" type="text" value="" size="30"/><br>
Your email:<br>
<input name="email" type="text" value="" size="30"/><br>
Your message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_POST['username'];
if (($department=="Email_0"))
{
$mailto=$_POST['example@website.com'];
}
if (($department=="Email_1"))
{
$mailto=$_POST['example@website.com'];
}
if (($department=="Email_2"))
{
$mailto=$_POST['example@website.com'];
}
else
{
$mailto=$_POST['example@website.com'];
}
$emailsubject=$_POST['emailsubject'];
$email=$_POST['email'];
$message=$_POST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill <a href=\"\">the form</a> again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Webform : $emailsubject";
mail($mailto, $subject, $message, $from);
echo "Thank you for your email! Your email has been sent, and we will try to respond as soon as we can!";
}
}
?>
我已修改基本表单以添加部门,这会更改联系表单的收件人。但在这样做的时候,表单似乎根本不再发送这些电子邮件。
任何人都知道我做错了什么?
答案 0 :(得分:1)
在这里你需要添加&#34; name =&#34; department&#34;&#34;到下面的代码
<select id="department" name="department" class="form-control-footer">
您需要在此处更改代码,如下所示:
if (($_POST['department'] == "Email_0"))
{
$mailto='example@website.com';
}
else if ($_POST['department'] == "Email_1")
{
$mailto = 'example@website.com';
}
...