简体   繁体   English

多收件人PHP电子邮件表单不发送电子邮件

[英]multi-recipient PHP email form not sending emails

I'm trying to get my email form working, but something seems to be hanging up. 我正在尝试使我的电子邮件表单正常运行,但是似乎挂了一些东西。 it's not sending out emails at all! 它根本不发送电子邮件!

For reference, this uses Wordpress, and this is the code: 供参考,它使用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!";
        }
    }  
?>

I've modified the base form to add in departments, which changes the recipient of the contact form. 我已经修改了基本表单以添加部门,从而更改了联系表单的收件人。 but in doing so, it seems the form no longer sends out those emails at all. 但是这样做似乎完全不再发送这些电子邮件。

Anyone know what I've done wrong? 有人知道我做错了吗?

Here you need to add "name="department"" to the code below 在这里,您需要在下面的代码中添加“ name =“ department”“

<select id="department" name="department" class="form-control-footer">

Here you need to change your code as showed below: 在这里,您需要更改代码,如下所示:

if (($_POST['department'] == "Email_0"))
{
    $mailto='example@website.com';
}
else if ($_POST['department'] == "Email_1")
{
    $mailto = 'example@website.com';
}
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM