drop down to e-mail

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • webandwe
    New Member
    • Oct 2006
    • 142

    drop down to e-mail

    Hi

    I want to make a php from where you got your normal fields and a drop down.

    However in the drop list i want to have like departments, sales, info, comment, ect.

    If I select sales from the drop down list and press submit then it must go to sale@mydomain.c om and if info is seleted it must go to info@mydomain.c om

    How I do this?

    Kind Regards
    Louwrens
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    If the variable of your drop down list selection is 'to_name' then something like. I use a switch statement because I don't know how many different adressees you have.
    [php]
    $sel = strip_tags(trim ($_POST['to_name']));
    switch ($sel) {
    case 'sales' : $to = 'sale@mydomain. com';
    break;
    case 'info' : $to = 'info@mydomain. com';
    break;
    default : echo 'You have an error';
    break;
    }
    // you use it in your mail statement as follows:
    mail($to, $subject, $message, $headers);
    [/php]

    Ronald :cool:

    Comment

    • webandwe
      New Member
      • Oct 2006
      • 142

      #3
      Hi Ronald

      I have gotten hold of just a normal php file which I can use wihtout the html page.

      Can you help me with this one, I inserted the code and try to make it work but now I get errors and I don't know what I am doing wrong.

      The orginal script before i started is below the line after my script.

      File name = list.php

      <html>
      <body><?php
      if (isset($_REQUES T['email']))
      //if "email" is filled out, send email
      {
      //send email
      $email = $_REQUEST['email'] ;
      $subject = $_REQUEST['subject'] ;
      $message = $_REQUEST['message'] ;

      mail($to, $subject, $message, $headers);
      $sel = strip_tags(trim ($_POST['to_name']));

      switch ($sel) {
      case 'louwrens' : $to = 'louwrens@mydom ain.com';
      break;
      case 'support' : $to = 'support@mydoma in.com';
      break;
      default : echo 'You have an error';
      break;
      echo "Your message has ben sent!";
      }
      //if "email" is not filled out, display the form
      {
      echo "<form method='post' action='list.ph p'>
      Email: <input name='email' type='text' /><br />
      Subject: <input name='subject' type='text' /><br />
      Message:<br />

      <textarea name='message' rows='15' cols='40'>
      </textarea><br />

      <input type='submit' />
      </form>";
      }
      ?></body>
      </html>


      ---------------------------------------------------------------------------------------------------------------

      File name = w3.php (original before I tried top inserted the script)

      <html>
      <body><?php
      if (isset($_REQUES T['email']))
      //if "email" is filled out, send email
      {
      //send email
      $email = $_REQUEST['email'] ;
      $subject = $_REQUEST['subject'] ;
      $message = $_REQUEST['message'] ;
      mail( "my@email.c om", "Subject: $subject",
      $message, "From: $email" );
      echo "Thank you for using our mail form";
      }
      else
      //if "email" is not filled out, display the form
      {
      echo "<form method='post' action='w3.php' >
      Email: <input name='email' type='text' /><br />
      Subject: <input name='subject' type='text' /><br />
      Message:<br />
      <textarea name='message' rows='15' cols='40'>
      </textarea><br />
      <input type='submit' />
      </form>";
      }
      ?></body>
      </html>

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Before you post read the Posting Guidelines at the top of the forum page!! Especially the part about showing code within code, php or html tags.

        I hope you don't expect me to read this unstructured display of code lines?

        Ronald :cool:

        Comment

        • webandwe
          New Member
          • Oct 2006
          • 142

          #5
          Hi Ronald

          Sorry I tought it auto formated, Well I inserted the tags, hope they work if they still wrong i'll do them again...But then you will have to give me some time cause I need to go for a while


          File name = list.php

          [PHP]<html>
          <body><?php
          if (isset($_REQUES T['email']))
          //if "email" is filled out, send email
          {
          //send email
          $email = $_REQUEST['email'] ;
          $subject = $_REQUEST['subject'] ;
          $message = $_REQUEST['message'] ;

          mail($to, $subject, $message, $headers);
          $sel = strip_tags(trim ($_POST['to_name']));

          switch ($sel) {
          case 'louwrens' : $to = 'louwrens@mydom ain.com';
          break;
          case 'support' : $to = 'support@mydoma in.com';
          break;
          default : echo 'You have an error';
          break;
          echo "Your message has ben sent!";
          }
          //if "email" is not filled out, display the form
          {
          echo "<form method='post' action='list.ph p'>
          Email: <input name='email' type='text' /><br />
          Subject: <input name='subject' type='text' /><br />
          Message:<br />

          <textarea name='message' rows='15' cols='40'>
          </textarea><br />

          <input type='submit' />
          </form>";
          }
          ?></body>
          </html>[/PHP]

          ---------------------------------------------------------------------------------------------------------------

          File name = w3.php (original before I tried top inserted the script)

          <html>
          <body>[PHP]<<?php
          if (isset($_REQUES T['email']))
          //if "email" is filled out, send email
          {
          //send email
          $email = $_REQUEST['email'] ;
          $subject = $_REQUEST['subject'] ;
          $message = $_REQUEST['message'] ;
          mail( "my@email.c om", "Subject: $subject",
          $message, "From: $email" );
          echo "Thank you for using our mail form";
          }
          else
          //if "email" is not filled out, display the form
          {
          echo "<form method='post' action='w3.php' >
          Email: <input name='email' type='text' /><br />
          Subject: <input name='subject' type='text' /><br />
          Message:<br />
          <textarea name='message' rows='15' cols='40'>
          </textarea><br />
          <input type='submit' />
          </form>";
          }
          ?>[/PHP]<</body>
          </html>

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            You mixed up the logic, issuing the sent message before the send and some more errors, like formgetting to fill the $headers var. I cleaned it up and gave some structure to it. It works.
            [php]<html>
            <body>
            <?php
            // initialize vars
            $error = '';
            $to = '';
            // -------------------------------------
            // if "email" is filled out, send email
            // -------------------------------------
            if (isset($_POST['email'])) {

            // cleanse and assign to-email address
            $email = strip_tags(trim ($_POST['email']));
            // cleanse and assign subject
            $subject = strip_tags(trim ($_POST['subject']));
            // cleanse and assign message text
            $message = strip_tags(trim ($_POST['message']));
            // set the address where it comes from
            $headers = 'MyUser@MySite. com';

            switch ($email) {
            case 'louwrens' : $to = 'louwrens@mydom ain.com';
            break;
            case 'support' : $to = 'support@mydoma in.com';
            default : break;
            } // End switch

            if ($to != '') {
            if (mail($to, $subject, $message, $headers)) {
            echo "Your email message has been sent!";
            exit;
            }
            else
            echo "Email could not be send.";
            } // End if ($to ..
            else
            $error = '<p>Invalid email address specified!</p>';
            } // End isset

            // ------------------------------------------------------
            // if "email" is not set or filled out, display the form
            // ------------------------------------------------------
            if ($error)
            echo "<span style='color:re d'>$error</span>";
            echo "<form method='post' action='a.php'>
            Email:
            <input name='email' type='text' value='$email' /><br />
            Subject:
            <input name='subject' type='text' value='$subject ' /><br />
            Message:<br />
            <textarea name='message' rows='15' cols='40'>$mess age</textarea><br />
            <input type='submit' value='Send email' />
            </form>";
            ?>
            </body></html>
            [/php]

            Ronald :cool:

            Comment

            • webandwe
              New Member
              • Oct 2006
              • 142

              #7
              Hi Ronald

              Can you please tell me what I am doing wrong with the drop down select. Cause I cannot get it to work if you like select a option to send it to a email for that option.

              I inserted it but for some reason I cannot get the thing to work. I removed all the stuff i tried and just left it as you gave it to me but with a drop down.

              [PHP]
              <html>
              <body>
              <?php
              // initialize vars
              $error = '';
              $to = '';
              // -------------------------------------
              // if "email" is filled out, send email
              // -------------------------------------
              if (isset($_POST['email'])) {

              // cleanse and assign to-email address
              $email = strip_tags(trim ($_POST['email']));
              // cleanse and assign subject
              $subject = strip_tags(trim ($_POST['subject']));
              // cleanse and assign message text
              $message = strip_tags(trim ($_POST['message']));
              // set the address where it comes from
              $headers = 'MyUser@MySite. com';

              switch ($email) {
              case 'louwrens' : $to = 'louwrens@greyp ebbles.com';
              break;
              case 'support' : $to = 'support@greype bbles.com';
              default : break;
              } // End switch

              if ($to != '') {
              if (mail($to, $subject, $message, $headers)) {
              echo "Your email message has been sent!";
              exit;
              }
              else
              echo "Email could not be send.";
              } // End if ($to ..
              else
              $error = '<p>Invalid email address specified!</p>';
              } // End isset

              // ------------------------------------------------------
              // if "email" is not set or filled out, display the form
              // ------------------------------------------------------
              if ($error)
              echo "<span style='color:re d'>$error</span>";
              echo "<form method='post' action='a.php'>
              Email:
              <select name="email" id="email">
              <option value="$louwren s">louwrens</option>
              <option value="$support ">support</option>
              </select>
              Subject:
              <input name='subject' type='text' value='$subject ' /><br />
              Message:<br />

              <textarea name='message' rows='15' cols='40'>$mess age</textarea><br />
              <input type='submit' value='Send email' />
              </form>";
              ?>
              </body></html>
              [/php]

              Comment

              • webandwe
                New Member
                • Oct 2006
                • 142

                #8
                Hi Ronald

                I got it working!!!! Thank you very much for your help.

                later.

                Comment

                • glady
                  New Member
                  • Nov 2006
                  • 23

                  #9
                  Originally posted by webandwe
                  Hi Ronald

                  I got it working!!!! Thank you very much for your help.

                  later.
                  Hi could you tell me if i select a drop down box value and press submit button it should go to two different mail boxes, is it possible, and if so, how to make it?
                  here is the code...
                  <td width="24%"><di v align="right">S elect Area:</div></td>
                  <td width="19%">
                  <select name="recipient " class="loginSel ect">
                  <option value=""></option>
                  <option value="gotocent ral@mydomain.co m">Central </option>
                  <option value="gotowest @mydomain.com"> West</option>
                  <option value="gotoeast @mydomain.com"> East</option>
                  </select>
                  </td>
                  --------------------------------
                  My question is, if i select West, it should send the mail to both west as well as central. Just like if i choose east, it should send mail to both east and central. So how can i set both values in single option value.
                  Something like
                  <option value="gotowest @mydomain.com"; "gotocentral@my domain.com">Wes t</option>
                  Thanks
                  glady

                  Comment

                  • ronverdonk
                    Recognized Expert Specialist
                    • Jul 2006
                    • 4259

                    #10
                    If you always send it to Central why bother to ask? Then your code could be:
                    [php]
                    switch ($email) {
                    case 'West' : $to = 'west@mydomain. com';
                    break;
                    case 'East' : $to = 'east@mydomain. com';
                    default : break;
                    } // End switch
                    // AND always to Central. MIND the comma!!
                    $to .= ", central@mydomai n.com";
                    [/php]
                    Ronald :cool:

                    Comment

                    • glady
                      New Member
                      • Nov 2006
                      • 23

                      #11
                      Originally posted by ronverdonk
                      If you always send it to Central why bother to ask? Then your code could be:
                      [php]
                      switch ($email) {
                      case 'West' : $to = 'west@mydomain. com';
                      break;
                      case 'East' : $to = 'east@mydomain. com';
                      default : break;
                      } // End switch
                      // AND always to Central. MIND the comma!!
                      $to .= ", central@mydomai n.com";
                      [/php]
                      Ronald :cool:
                      Actually i am using FormMail.pl in php-nuke, so i dont need to get any email address from the person who submits the form by choosing the area and filling other form details.
                      The form contains some information need to be filled by choosing the area, and then submit.If the person choose central it should go to central@mydomai n.com,
                      if the person chooses east, and click submit button, it should me mailed to east as well as central.
                      east@mydomain.c om,central@mydo main.com
                      likewise if the user selects west and submit the form, the mail should be sent to
                      west@mydomain.c om,central@mydo main.com
                      I have coding like,
                      <td width="24%"><di v align="right">S elect Area:</div></td>
                      <td width="19%">
                      <select name="recipient " class="loginSel ect">
                      <option value=""></option>
                      <option value="central@ mydomain.com">C entral </option>
                      <option value="west@myd omain.com">West </option>
                      <option value="east@myd omain.com">East </option>
                      </select>
                      </td>

                      Do i need to change the option value for west and east like
                      <option value="central@ mydomain.com">C entral</option>
                      <option value="$West">W est</option>
                      <option value="$East">E ast</option>
                      </select>
                      switch(what needs to be given){
                      case 'West' : $to='west@mydom ain.com';
                      break;
                      case 'East' : $to='east@mydom ain.com';
                      break;
                      default :break;
                      }
                      $to .=",central@myd omain.com";
                      Thanks

                      Comment

                      • ronverdonk
                        Recognized Expert Specialist
                        • Jul 2006
                        • 4259

                        #12
                        I have told you before to enclose your code within code, php or html tags. If you keep persisting on NOT DOING that I will exclude your questions/replies!

                        Ronald :cool:

                        Comment

                        • glady
                          New Member
                          • Nov 2006
                          • 23

                          #13
                          Originally posted by ronverdonk
                          I have told you before to enclose your code within code, php or html tags. If you keep persisting on NOT DOING that I will exclude your questions/replies!

                          Ronald :cool:
                          Sorry and i will keep that in mind and post questions accordings,
                          Thanks.

                          Comment

                          • glady
                            New Member
                            • Nov 2006
                            • 23

                            #14
                            Originally posted by glady
                            Sorry and i will keep that in mind and post questions accordings,
                            Thanks.
                            Again i will post in acorrect format
                            Actually i am using FormMail.pl in php-nuke, so i dont need to get any email address from the person who submits the form by choosing the area and filling other form details.
                            The form contains some information need to be filled by choosing the area, and then submit.If the person choose central it should go to central@mydomai n.com,
                            if the person chooses east, and click submit button, it should me mailed to east as well as central.
                            east@mydomain.c om,central@mydo main.com
                            likewise if the user selects west and submit the form, the mail should be sent to
                            west@mydomain.c om,central@mydo main.com
                            I have coding like,
                            Code:
                            [HTML]
                            <td width="24%"><div align="right">Select Area:</div></td>
                            <td width="19%">
                            <select name="recipient" class="loginSelect">
                            <option value=""></option>
                            <option value="central@mydomain.com">Central </option>
                            <option value="west@mydomain.com">West</option>
                            <option value="east@mydomain.com">East</option>
                            </select>
                            </td>
                            [/HTML]
                            Do i need to change the option value for west and east like
                            Code:
                            [HTML]
                            <option value="central@mydomain.com">Central</option>
                            <option value="$West">West</option>
                            <option value="$East">East</option>
                            </select>
                            switch(what needs to be given){
                            case 'West' : $to='west@mydomain.com';
                            break;
                            case 'East' : $to='east@mydomain.com';
                            break;
                            default :break;
                            }
                            $to .=",central@mydomain.com";
                            [/HTML]
                            is that ok/?
                            Thanks

                            Comment

                            • ronverdonk
                              Recognized Expert Specialist
                              • Jul 2006
                              • 4259

                              #15
                              The following looks the easiest solution to this. Since you always send to central, you can fill in that address. If one chooses another destination: just concatenate it to the existing address in $to. As follows:
                              [php]<option value="Central" >Central</option>
                              <option value="West">We st</option>
                              <option value="East">Ea st</option>
                              </select>
                              .....
                              // assign the variables from the POST or GET array
                              ......
                              $to = 'central@mydoma in.com';
                              switch(what needs to be given)
                              {
                              case 'West' : $to .= ', west@mydomain.c om';
                              break;
                              case 'East' : $to .= ', east@mydomain.c om';
                              break;
                              default : break;
                              }[/php]
                              Don't forget you have to assign the values from the drop-down box to the 'what needs to be given' variable from the $_POST or $_GET array!

                              Ronald :cool:

                              Comment

                              Working...