Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: PHP Mailing Different People

  1. #1
    Join Date
    Oct 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation PHP Mailing Different People

    Hello people,

    I would like to say thank you to all of you that are providing scripts and answers to questions here on the forums. I have a question, or a challenge as some of you may take it. I started using PHP a few days ago for this company I work for. They have a contact us page that has 2 drop down lists. One of them are :

    I am a/an :
    "Prospective insured"
    "Prospective agent"
    "Insured"
    "Agent"
    "Uknown Person"

    I wish to :
    "Request Claim Information"
    "Request information about my policy"
    "Request information about obtaining my policy"
    "Request my password"
    "Comment on your website"
    "Contact you on an unlisted topic"

    These are the two drop downs included in the html form. When the user submits, it sends an email using php to mail a specfic user inlcuding all the information selected/inputted into the form.
    The thing I need done is for when they select something under Drop Down 1, and then something from Drop Down 2, i need it to mail to a specific email based on the choises in the drop down.
    I started to make arrays and what not but I just cant follow. Is it possible for someone to post a script that will do something like this, or atleast post me the building blocks that I can easily alter to get this form to work properly?

  2. #2
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    PHP Code:
    <?
    /* The skeleton */

    $who $_POST['who'];
    $typeOfInfo $_POST['typeOfInfo'];

    $nameOfWho = array(
        
    "pinsured" => "Prospective insured",
        
    "pagent" => "Prospective agent",
        
    "insured" => "Insured",
        
    "agent" => "Agent",
        
    "unknown" => "Uknown Person");

    $nameOfInfo = array(
        
    "Request Claim Information",
        
    "Request information about my policy",
        
    "Request information about obtaining my policy",
        
    "Request my password",
        
    "Comment on your website",
        
    "Contact you on an unlisted topic");


    $list = array(
        
    "john.doe@mail.com",
        
    "Homer.Sexual@moes.com",
        
    "trustno1@aol.com"
    ); /* for gathering addresses of interested parties */

    switch ($who) {
        case 
    "pinsured" :
            
    $mailing "$list[0]$list[3]";
            break;
        case 
    "insured" :
            
    $mailing $list[2];
            break;
    /* blah, blah, blah so on, so forth */
        
    default:
            die(
    "You should select who you are");
    }

    $post "$name, a "$nameOfWho[$who].
        
    " wants to "$nameOfInfo[$typeOfInfo] .
        
    ":
        Additional comment was:
        
    $comment\n";

    mail($mailing,
        
    "An information requested",
        
    $post) or die("Mail session failed! The query was not sent, contact the administrator");
    ?>
    Last edited by ItsMeOnly; 10-30-2006 at 07:50 PM.

  3. #3
    Join Date
    Oct 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The user selects something out of the drop downs but gets you should sleect who you are. What is the cause of this?
    Last edited by lesham; 10-30-2006 at 08:17 PM.

  4. #4
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by lesham
    im not following the whole switch part... i put it out there how it is, and tested it to see what i was working with and it said "You should select who you are" but i did select. feel like helping me out some more?
    The idea will work if you have form ready, will not work if you don't

    <FORM action="myscript.php" method="post">
    <SELECT NAME="who">
    <OPTION VALUE="pinsured">Prospective insured</option>
    <OPTION VALUE="pagent">Prospective agent</option>
    <OPTION VALUE="insured">Insured</option>
    <OPTION VALUE="agent">Agent</option>
    <OPTION VALUE="unknown" selected="selected">Uknown Person</option>
    </SELECT>
    <select name="typeOfInfo">
    <OPTION VALUE="0">Request Claim Information</option>
    <OPTION VALUE="1">Request information about my policy</option>
    <OPTION VALUE="2">Request information about obtaining my policy</option>
    <OPTION VALUE="3">Request my password</option>
    <OPTION VALUE="4">Comment on your website</option>
    <OPTION VALUE="5">Contact you on an unlisted topic</option>
    </select>
    <input type="submit" value="Send query">
    </form>

  5. #5
    Join Date
    Oct 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\Inetpub\wwwroot\contactus.php on line 57
    Mail session failed! The query was not sent, contact the administrator

    know what this is from?

    line 57= $post) or die("Mail session failed! The query was not sent, contact the administrator");

  6. #6
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    It means that you didn't read installation notes :-p


    but seriously, you need to set several defaults in your php installation, creating a php.ini file- you can also add 4th parameter to mail(), which is "From: me@mydomain.net"

  7. #7
    Join Date
    Oct 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This code is great, works effectively, but... What im trying to do is to form a matrix of some sort, i want a combination of selections, like if i was a pinsured who chose password, i want it to go to a support team, but if i was a pinsured who chose request claim information, i want it to send elsewhere... u know? it seems it only sends to just the first drop down entry, not a combination...

    p.s. the issue i had before was fixed, damn ; (commented out)

  8. #8
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by lesham
    What im trying to do is to form a matrix of some sort
    That's where case comes in, if you wanna build on type of support, you'll need change switch() parameter to $typeOfInfo, and rebuild cases. You will have 6 (from 0 and 5) cases /and default, if needed/.

    You can combine case, like
    PHP Code:
    case :
    case 
    :
        
    $mailing "$list[2]$list[3]";
        break;
    case 
    :
       
    $mailing $list[0];
       break; 
    Last edited by ItsMeOnly; 10-30-2006 at 09:33 PM.

  9. #9
    Join Date
    Oct 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Well i suppose i get what you are saying, although it seems like its one or the other and not both. Either send an email based on who it is , or what type of info. I do not have the current emails that are going to be used for this, maybe the emails will be simple enough that i can send them based on the type of info. If not, im going to have to find an alternative way to do this. Thanks alot for the help, i have been plugging away at this for a week haha

  10. #10
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by lesham
    Well i suppose i get what you are saying, although it seems like its one or the other and not both. Either send an email based on who it is , or what type of info.
    Case inside case, or, external referencing via building a two-dimentional array
    containing the "caretakers" for specific groups of clients: basically we're now entering relational databases, but it can be done with just smart programming
    PHP Code:
    $typeOfInfoPeople = array(
    /*            pinsured, pagents, insured, agents, unknown */
    => array("$list[0]$list[2]/* note the parenthesis*/
                                 
    NULLNULLNULLNULL),
    => array(NULL$list[2], NULLNULLNULL)
    /* etc */

    Now, to build $mailing, you can just reference the desired element of such "mega array"., like $mailing = $typeOfInfoPeople[$typeOfInfo][$who]. Ah, one thing, the "NULLs" should be verified before trying to mail to no address.
    it's best just to
    PHP Code:
    if (!$mailing) die("We apologize. For the moment, we cannot provide feedback for "$typeOfWho[$who]);
    else {
       
    mail()

    Last edited by ItsMeOnly; 10-30-2006 at 10:02 PM.

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
  •