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

时间:2022-03-27 07:26:48

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?

谁知道我做错了什么?

1 个解决方案

#1


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';
}
...

#1


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';
}
...