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 9 of 9
  1. #1
    Junior Member
    Join Date
    Jul 2005
    Posts
    12
    Member #
    10480
    I am very new to php, and have been fussing with a form to send an email. Right now I have it working in that I can send the email to one email address. I would like to change it so that the email is sent to a different address, depending on the selection in a drop down box (For example, if they select "Mailing List" it gets sent to "mailinglist@mydomain.com", but if they select "Owners", the email is sent to "owners@mydomain.com). I would really appreciate if someone could advise me on how to proceed.

    Thanks!

    Here is the code for the selection box:

    Attention:
    HTML Code:
    <select name="attn" size="1">
    <option value="Mailing_List">Mailing List</option>
    <option value="owner">Owners</option>
    <option value="Class_Signup">Class Signup</option>
    <option value="Order">Ordering Request</option>
    <option value="Links_Exchange">Links Exchange</option>
    <option value="Other">Other</option>
    </select>
    and here is the entire php:

    PHP Code:
    <?php
    $name 
    $_POST['name']; 
    $email $_POST['email']; 
    $comments $_POST['comments'];
    $attn $_POST['attn'];
    ?> 

    <html>
    <head>
    <title>Message Sent</title>
    <link rel="stylesheet" type="text/css" href="../style.css">
    </head>
    <body>


    <?php
    if(!$email == "" && (!strstr($email,"@") || !strstr($email,"."))) 
    {
    echo 
    "<h2>Use Back - Enter valid e-mail</h2>\n"
    $badinput "<h2>Your message was not sent.</h2>\n";
    }
    if(empty(
    $name) || empty($email) || empty($comments )) {
    echo 
    "<h2>Use Back - fill in all fields</h2>\n";
    }
    echo 
    $badinput;

    $todayis date("l, F j, Y, g:i a") ;

    $attn $attn 
    $subject $attn

    $comments stripcslashes($comments); 

    $message $todayis [EST] \n
    From: 
    $name ($email)\n
    Message: 
    $comments \n 
    "
    ;

    $from "From: $email\r\n";


    mail("website@mydomain.com"$subject$message$from);

    ?>

    <p align="center">
    <?php echo $todayis ?> 
    <br /><br />
    Thank You <?php echo $name ?>  
    <br /><br />

    Your Message:<br /> <br />
    <?php $commentsout str_replace("\r""<br/>"$comments); 
    echo 
    $commentsout?> 
    <br /><br />has been sent!

    <br /><br />
    <a href="http://www.mydomain.com"> Home Page </a> 
    </p> 

    </body>
    </html>

  2.  

  3. #2
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Change the hardcoded email address in the [phpfunction]mail[/phpfunction] function to the variable containing the selected email address.

    If the "attn" variable is the one to be used, then change the options to contain the email addresses:
    [minicode]<option value="owner@mydomain.com">Owners</option>[/minicode]

    then in the mail function:
    [minicode] mail($attn, $subject, $message, $from); [/minicode]

    Your title reads "multiple recipients". If you want to send the same mail to multiple recipients, you just seperate the different recipients by comma:
    [minicode]$attn = "aa@site.com, ba@site.com, ca@site.com, ...";[/minicode]
    S. Rosland

  4. #3
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Change your HTML to this
    HTML Code:
    <select name="attn" size="1">
    <option value="mailinglist">Mailing List</option>
    <option value="owner">Owners</option>
    <option value="class">Class Signup</option>
    <option value="order">Ordering Request</option>
    <option value="links">Links Exchange</option>
    <option value="other">Other</option>
    </select>
    This way we can just include the superglobal variable instead of getting into the situation of if statements/case statement.

    Now, change your php to:
    PHP Code:
    <?php
    $name 
    $_POST['name'];
    $email $_POST['email'];
    $comments $_POST['comments'];
    $attn $_POST['attn'];
    ?>

    <html>
    <head>
    <title>Message Sent</title>
    <link rel="stylesheet" type="text/css" href="../style.css">
    </head>
    <body>


    <?php
    if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")))
    {
    echo 
    "<h2>Use Back - Enter valid e-mail</h2>\n";
    $badinput "<h2>Your message was not sent.</h2>\n";
    }
    if(empty(
    $name) || empty($email) || empty($comments )) {
    echo 
    "<h2>Use Back - fill in all fields</h2>\n";
    }
    echo 
    $badinput;

    $todayis date("l, F j, Y, g:i a") ;

    $attn $attn;
    $subject $attn;

    // i added this line
    $to "$attn@mydomain.com";

    $comments stripcslashes($comments);

    $message $todayis [EST] \n
    From: 
    $name ($email)\n
    Message: 
    $comments \n
    "
    ;

    $from "From: $email\r\n";


    mail($to$subject$message$from);

    ?>

    <p align="center">
    <?php echo $todayis ?>
    <br /><br />
    Thank You <?php echo $name ?>  
    <br /><br />

    Your Message:<br /> <br />
    <?php $commentsout str_replace("\r""<br/>"$comments);
    echo 
    $commentsout?>
    <br /><br />has been sent!

    <br /><br />
    <a href="http://www.mydomain.com"> Home Page </a>
    </p>

    </body>
    </html>
    So now, $to will get whatever option value is chosen, as well as @mydomain.com.
    Then in the mail() call, give it $to.

    Hope this helps

  5. #4
    Junior Member
    Join Date
    Jul 2005
    Posts
    12
    Member #
    10480
    Thank You so very much, Rosland and bfsog. I really appreciate the clear instructions and examples. Understanding php has been more difficult than I care to admit.I tried both examples, and not only did they both work, but I actually understood why they worked! Thank you both!

    Rosland--thanks for the extra tidbit on multiple recipients--I guess my phrasing was a bit confusing. But I will be noting that for future reference!

    bsfrog--the reason I had the option value as "Mailing_List" is because I have $subject=$attn. By using your values, the subject becomes "mailinglist@mydomain.com", instead of "Mailing_List".

    So here's the next logical question--how would I go about adding the variable for the subject so that it is different than $attn?

    Thanks in advance!

  6. #5
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Okay, we will stick with your original HTML
    HTML Code:
    <select name="attn" size="1">
    <option value="Mailing_List">Mailing List</option>
    <option value="Owner">Owners</option>
    <option value="Class_Signup">Class Signup</option>
    <option value="Order">Ordering Request</option>
    <option value="Links_Exchange">Links Exchange</option>
    <option value="Other">Other</option>
    </select>
    And heres your revised PHP:
    PHP Code:
    <?php
    $name 
    $_POST['name'];
    $email $_POST['email'];
    $comments $_POST['comments'];
    $attn $_POST['attn'];
    ?>

    <html>
    <head>
    <title>Message Sent</title>
    <link rel="stylesheet" type="text/css" href="../style.css">
    </head>
    <body>


    <?php
    if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")))
    {
    echo 
    "<h2>Use Back - Enter valid e-mail</h2>\n";
    $badinput "<h2>Your message was not sent.</h2>\n";
    }
    if(empty(
    $name) || empty($email) || empty($comments )) {
    echo 
    "<h2>Use Back - fill in all fields</h2>\n";
    }
    echo 
    $badinput;

    $todayis date("l, F j, Y, g:i a") ;

    $subject $attn;
    if(
    $attn == "Mailing_List")
         
    $to "mailinglist@mydomain.com";
    if(
    $attn == "Owner")
         
    $to "owner@mydomain.com";
    if(
    $attn == "Class_Signup")
         
    $to "class@mydomain.com";
    if(
    $attn == "Order")
         
    $to "order@mydomain.com";
    if(
    $attn == "Links_Exchange")
         
    $to "links@mydomain.com";
    if(
    $attn == "Other")
         
    $to "other@mydomain.com";

    $comments stripcslashes($comments);

    $message $todayis [EST] \n
    From: 
    $name ($email)\n
    Message: 
    $comments \n
    "
    ;

    $from "From: $email\r\n";


    mail($to$subject$message$from);

    ?>

    <p align="center">
    <?php echo $todayis ?>
    <br /><br />
    Thank You <?php echo $name ?>  
    <br /><br />

    Your Message:<br /> <br />
    <?php $commentsout str_replace("\r""<br/>"$comments);
    echo 
    $commentsout?>
    <br /><br />has been sent!

    <br /><br />
    <a href="http://www.mydomain.com"> Home Page </a>
    </p>

    </body>
    </html>
    So $subject is $attn and $attn is either Mailing_List, Owner, Class_Signup, Order, Links_Exchange, Other.

    Hope this helps.

  7. #6
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Your question is so simple, that I'm afraid I might have misunderstood.

    If you need a predefined subject title, then just add it in your options menu!

    You collect the information the same way as you have all the other variables [minicode]$subject = $_POST['subject'];[/minicode]
    ______

    If you want to combine the subject and the mail address into one package, just use bfsog's example.
    (if mail about squirrels should go to squirrels@site.com, then set the variable $attn to hold the value 'squirrels'.
    Then you can use that both in the subject field and the mail address.
    [minicode]$subject = $_POST['attn'] [/minicode] and [minicode] $to = "$attn@site.com"[/minicode]
    S. Rosland

  8. #7
    Junior Member
    Join Date
    Jul 2005
    Posts
    12
    Member #
    10480
    Thank you both! I realize that my questions are so basic as to seem silly, and I really appreciate that you both took the time to assist me. I have only used php once before, also with a downloaded script I adjusted to suit what I needed at the time.

    I thought I could get by with just knownig HTML, but have come to the realization that I really must learn php, so I am working with the Sam's Book, and it is starting to make sense!

    Thanks again for the help! Not many would be willing to offer help with something so simple without being condescending.

  9. #8
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Your questions so far has been to the point. NOTHING you've said indicate stupidity. Coding can be a daunting task if you've never done it before.
    Don't be intimidated by lack of knowledge. No question is stupid. If you feel that anything so far said in this thread is incomprehencible, feel free to say so!

    Any questions you might have (stupid or whatever), will be dealt with in a polite tone!

    No questions are silly. If you manage to produce one however, I'll personally guarantee you that it will be dealt with in a non-condescending way!

    Feel free to ask ANYTHING you feel uncertain of. There are a lot of highly skilled members here, and they are all happy to be of assistance!
    That's the whole purpose of these forums!

    S. Rosland

  10. #9
    Junior Member
    Join Date
    Jan 2006
    Posts
    3
    Member #
    12315
    Thanks
    I was also having problem , but this script worked.


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
  •  

Search tags for this page

drop down with multiple recipents in php contact form

Click on a term to search for related topics.
All times are GMT -6. The time now is 09:56 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com