PHP -Send Multiple E mails - when submit the form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Harshpandya
    New Member
    • Jun 2007
    • 30

    PHP -Send Multiple E mails - when submit the form

    Hi all,

    I am working on the form in which you fill out the whole PHP form and e mail that details to someone. It is working fine. But now i want to send the same form to be sent to different people and user should be able choose the check boxes to whom they want to send e mail to.

    I write some code simple If else conditions but i think i am making some mistakes. Because when i tried - it is not sending them e mails.

    Here is my code. I have 2 files. 1 is the HTML form and second is the PHP files.

    HTML FORM:----------------------I put the check boxes. - I want the user to choose the check boxes to whom user want to send E mail.
    [code=html]
    <td><strong>E mail Send to:</strong> </td>
    <td colspan="2">
    <input name="send" type="checkbox" value="Harsh">
    Harsh
    <input name="send" type="checkbox" value="Abbey">
    Abbey
    <input name="send" type="checkbox" value="Michelle ">
    Michelle
    </td>[/code]

    HERE IS MY PHP CODE:--------------------------------

    [code=php]<?php

    $subject = "Catch of the Week- Name--".$_POST["Name"]."\n";

    $message = ' Employee Firstname--'.$_POST["employee_first name"]."\n".' Employee Lastname--'.$_POST["employee_lastn ame"]."\n".'Work Area--'.$_POST["work"]."\n".' Nominated For--'.$_POST["nominated"]."\n".'Comme nts--'.$_POST["comments"]."\n".' Name of Sender--'.$_POST["Name"]."\n".'Addre ss--'.$_POST["Address"]."\n".'Phone Number--'.$_POST["phone_numb er"]."\n";
    $headers = 'From: webmaster@' . $_SERVER['SERVER_NAME'] . "\r\n" .
    'Reply-To: webmaster@' . $_SERVER['SERVER_NAME'] . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
    if($subject)
    {

    elseif($send == "Harsh")
    {
    mail("hpandya@c sufresno.edu", $subject, $message, $headers);
    }

    elseif($send == "Abbey")
    {
    mail("hnpandya2 002@yahoo.com", $subject, $message, $headers);
    }

    elseif($send == "Michelle")
    {
    mail("", $subject, $message, $headers);
    }

    elseif($send == "Harsh")
    {
    mail("housingwe bmaster@listser v.csufresno.edu ", $subject, $message, $headers);
    }

    echo "Thank you for nominating a staff member for our Catch of Week Drawing. Winners are drawn every Friday. You can check Housing Happenings for a list of the winners, and who nominated them. If your nomination form is complete and drawn, you win a Movie Ticket.";
    }
    else
    echo "failed";
    ?> [/code]

    [Please use CODE tags when posting source code. Thanks! --pbmods]
    _______________ _______________ _______________ ___________

    I have added HARSH - ABBEY and MIchelle - as check boxes but its not working when i submit. Remember it was working for only one person so when i added multiple people it is not working so the problem might be in IF Else conditions.

    Thanks,
    Please Help - I would Appreciate it.
    Harsh
    (I would never give up.....)
  • epots9
    Recognized Expert Top Contributor
    • May 2007
    • 1352

    #2
    the way elseif works is if the first one is true it doesn't check the rest. u should have single if statements for each one to get it to work.

    and your starting an elseif in the body of an if statement with no beginning if
    yours:
    [PHP]
    if(...)
    {
    elseif(..)
    }
    }
    [/PHP]

    should be:
    [PHP]
    if(...)
    {
    if(..)
    {
    }
    elseif(..)
    {
    }
    }
    [/PHP]

    good luck

    Comment

    • Harshpandya
      New Member
      • Jun 2007
      • 30

      #3
      Originally posted by epots9
      the way elseif works is if the first one is true it doesn't check the rest. u should have single if statements for each one to get it to work.

      and your starting an elseif in the body of an if statement with no beginning if
      yours:
      [PHP]
      if(...)
      {
      elseif(..)
      }
      }
      [/PHP]

      should be:
      [PHP]
      if(...)
      {
      if(..)
      {
      }
      elseif(..)
      {
      }
      }
      [/PHP]

      good luck


      For some reason it it still not working - i tried changing the "if else" conditions but not working.

      Please Help,

      Thanks,
      Harsh

      Comment

      • epots9
        Recognized Expert Top Contributor
        • May 2007
        • 1352

        #4
        your checkboxes have the same name (name="send"), give them different names, use different variable for each checkbox in your php code.

        When u submit the form it isn't sends all the checkboxes that were checked, just the last one cuz they all have the same reference.

        or u can try (not 100% sure this will work):
        [PHP]$_POST["send"][0][/PHP]
        or get.

        Comment

        • mwasif
          Recognized Expert Contributor
          • Jul 2006
          • 802

          #5
          Use $_POST["send"] instead of $send in if else.

          Comment

          • mwasif
            Recognized Expert Contributor
            • Jul 2006
            • 802

            #6
            Your script can send email to only one person. To send mail to multiple persons change the checkbox name to send[] for each checkbox.

            <input name="send[]" ...

            And use the below code to see if use selected the checkbox or not

            if( in_array("Harsh ", $_POST["send"]) )
            mail(... // send mail

            if( in_array("Abbey ", $_POST["send"]) )
            mail(... // send mail

            Comment

            • Harshpandya
              New Member
              • Jun 2007
              • 30

              #7
              Originally posted by mwasif
              Your script can send email to only one person. To send mail to multiple persons change the checkbox name to send[] for each checkbox.

              <input name="send[]" ...

              And use the below code to see if use selected the checkbox or not

              if( in_array("Harsh ", $_POST["send"]) )
              mail(... // send mail

              if( in_array("Abbey ", $_POST["send"]) )
              mail(... // send mail

              you guys are awesome


              Thanks a Bunch

              Comment

              Working...