Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    3
    Member #
    32510
    [SIZE=21px]I have a very simple Email Form Script and wish to add a drop down menu to choose who to send it to?[/SIZE]

    I don't know heaps on PHP (if really any)
    But I am quite confident on HTML
    I am making a site for my work and they require a drop down menu so we can select what person the email needs to get to.
    So if anyone can help and tell me how to add the drop down and what to change/add in the PHP that would be amazing.

    Here is the HTML:
    <form action="contact.php" method="post">
    <p>Your name

    <input type="text" name="cf_name">
    </p>
    <p>Your e-mail

    <input type="text" name="cf_email">
    </p>
    <p>
    Message

    <textarea name="cf_message"></textarea>
    </p>
    <p>
    <input type="submit" value="Send">
    <input type="reset" value="Clear">
    </p>
    </form>

    And here is the PHP:
    <?php
    $field_name = $_POST['cf_name'];
    $field_email = $_POST['cf_email'];
    $field_message = $_POST['cf_message'];

    $mail_to = 'sdfsddsf';
    $subject = 'Webform Email '.$field_name;

    $body_message = 'From: '.$field_name."\n";
    $body_message .= 'E-mail: '.$field_email."\n";
    $body_message .= 'Message: '.$field_message;

    $headers = 'From: '.$field_email."\r\n";
    $headers .= 'Reply-To: '.$field_email."\r\n";

    $mail_status = mail($mail_to, $subject, $body_message, $headers);

    if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
    alert('Thank you for the message. We will contact you shortly.');
    window.location = 'contact.html';
    </script>
    <?php
    }
    else { ?>
    <script language="javascript" type="text/javascript">
    alert('Message failed. Please, send an email to dfsdfsdfsdf');
    window.location = 'contact_page.html';
    </script>
    <?php
    }
    ?>

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    Do you want people to know (or see) the recipient emails?
    Or do you want them to remain somewhat private?

    If you display any of them on the HTML form, that means
    anyone (including spammers) can see the email addresses.

    Describe the project and how private or secure it needs to be.


  4. #3
    Junior Member
    Join Date
    Aug 2012
    Posts
    3
    Member #
    32510
    Quote Originally Posted by mlseim, post: 240374
    Do you want people to know (or see) the recipient emails?
    Or do you want them to remain somewhat private?

    If you display any of them on the HTML form, that means
    anyone (including spammers) can see the email addresses.

    Describe the project and how private or secure it needs to be.
    It would be great to stay private.
    This is my first time using PHP.
    I'm making a site for my work and since email is main way of getting clients and something we use everyday it would be quite a pain if there were spammers.
    So if you could show me how to change that as well that would be great.

    There is 3 emails that would go into the form to select from if that is any help.
    And we just want the three names to pop down on the menu of recipients.

    Thanks

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    Make the form first ...

    <select name="recip">
    <option value="0">All Names</option>
    <option value="1">John Smith</option>
    <option value="2">Jane Doe</option>
    <option value="3">Bill Anderson</option>
    </select>

    In your PHP script you would get the value of "recip" and
    create the "sendto" string.

    $r=$_POST['recip'];

    $mail_to="jsmith@aol.com;jdoe@gmail.com;billander@comcast.com";
    if($r==1){
    $mail_to="jsmith@aol.com";
    }
    if($r==2){
    $mail_to="jdoe@gmail.com";
    }
    if($r==3){
    $mail_to="billander@comcast.com";
    }

    Sort of like that ... and you have the rest of the email script


  6. #5
    Junior Member
    Join Date
    Aug 2012
    Posts
    3
    Member #
    32510
    Quote Originally Posted by mlseim, post: 240496
    Make the form first ...

    <select name="recip">
    <option value="0">All Names</option>
    <option value="1">John Smith</option>
    <option value="2">Jane Doe</option>
    <option value="3">Bill Anderson</option>
    </select>

    In your PHP script you would get the value of "recip" and
    create the "sendto" string.

    $r=$_POST['recip'];

    $mail_to="jsmith@aol.com;jdoe@gmail.com;billander@comcast.com";
    if($r==1){
    $mail_to="jsmith@aol.com";
    }
    if($r==2){
    $mail_to="jdoe@gmail.com";
    }
    if($r==3){
    $mail_to="billander@comcast.com";
    }

    Sort of like that ... and you have the rest of the email script
    Thats for this.
    Worked like a charm!!
    Thought I was never going to get it to work


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 02:31 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com