Kizzycocoa
Kizzycocoa

Reputation: 39

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:

<?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['[email protected]'];
        }
    if (($department=="Email_1"))
    {
        $mailto=$_POST['[email protected]'];
        }
    if (($department=="Email_2"))
    {
        $mailto=$_POST['[email protected]'];
        }
    else
    {
        $mailto=$_POST['[email protected]'];
        }

    $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?

Upvotes: 0

Views: 87

Answers (1)

SoftGuide
SoftGuide

Reputation: 336

Here you need to add "name="department"" to the code below

<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='[email protected]';
}
else if ($_POST['department'] == "Email_1")
{
    $mailto = '[email protected]';
}
...

Upvotes: 1

Related Questions