Results 1 to 5 of 5

Thread: Mail Script Help

  1. #1
    Join Date
    Nov 2006
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Mail Script Help

    How do I make a PHP script so that there is a drop down menu with a list of names. Depending on the name/selection that the user selects it will send the e-mail to a different person. Also, how do I make it so that the form has a spot for a subject that the user can input?

    For the subject I would like the subject in the e-mail to actually appear as "[Site Contact Us]_USER_SUBMITTED_SUBJECT_" Are either of these even possible?

    -GT

  2. #2
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    we'll need your code to modify it for you.
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  3. #3
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Use the following codes as an example, and edit to your liking.

    test.html

    Code:
    <html>
    <head>
    <title>Contact Us</title>
    </head>
    <body>
    
    <form action="mailer.php" method="POST">
    <input type="hidden" name="act" value="mail_it">
    
    Your Name: <input type="text" name="name"> <BR>
    
    Your Email: <input type="text" name="email"> <BR>
    
    Subject: <input type="text" name="subject"> <BR>
    
    Who do you wish to contact?<BR>
    <select name="mailto">
    <option value="">-- Choose One --</option>
    <option value="john">John Smith</option>
    <option value="ashley">Ashley M.</option>
    <option value="accounting">Accounting</option>
    </select>
    
    <BR>
    
    Message: <textarea cols="30" rows="10" name="message"></textarea>
    
    <BR>
    
    <input type="submit" value="Send Message">
    </body>
    </html>
    mailer.php

    PHP Code:
    <?php

    $site 
    "http://mydomain.com/contact.php"//your website url to redirect to


    /* Edit the following array! Be sure to keep the format 
     'select option name' => 'select option email address'
    Ex: 'john' => 'john@mydomain.com', ...*/

    $to = array(
    'john' => 'john@mydomain.com',
    'ashley' => 'ashley@mydomain.com',
    'accounting' => 'accounting@mydomain.com'
    );

    /*no need to edit below this*/

    $name $_REQUEST[name];
    $email $_REQUEST[email];
    $mailto $_REQUEST[mailto];
    $subject $_REQUEST[subject];
    $message $_REQUEST[message];
    $act $_REQUEST[act];


    if (
    $act == "mail_it") {

    $sendto $to[$mailto];
    $sub '[Site Contact Us]_'.$subject;

    $send mail($sendto$sub$message);

       if (
    $send) {

    header('Refresh: 2; url='.$site);

    echo 
    'Your message was sent successfully and you will recieve a response ASAP!';

       }

       else {

    header('Refresh: 2; url='.$site);

    echo 
    'Your message was not sent! Please try again.';

       }

    }

    else {
    header('Location: '.$site); //redirects user back to your website
    }
    ?>
    I haven't tested it out, but it should work. Let me know if you need any more help.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Ok, the above code that I posted has been tested and it works fine. Let me know if you experience any problems with it, or if you need any more help on this matter.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Nov 2006
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Alright, thanks! I have not been able to add it to my site yet, because the other guy in my web team hasn't registered on the host yet. But I will definately notify you if something doesn't work!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •