SitePoint Sponsor

User Tag List

Results 1 to 25 of 25
  1. #1
    SitePoint Evangelist
    Join Date
    May 2005
    Location
    Houston, Texas, USA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Need php contact script that can go to 2 addresses

    Hello-- I'm not a programmer. The client I have is free so I have no money to pay, but have lots of appreciation to give! My problem is I have a PHP script that works great, however, there are several choices in the "Attention" field. The customer wants some of the choices, like Sales and Billing to go to one email address and the others, like Tech Support and Other to go to another email address, both from his domain.Can anyone help me accomplish this without creating more than one input document?

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    One solution would be to store the different emails in an array, and then use the selected value to determine which email that the message should be sent to. First, let's start with the user interface - the list of choices:

    HTML Code:
    <select name="attention">
     <option value="sales">Sales</option>
     <option value="billings">Billings</option>
    </select>
    The next step is to create the array holding the addresses:

    PHP Code:
    $emails = array(
        
    'sales' => 'sales@a-domain.com',
        
    'billings' => 'billings@another-domain.com'
      
    ); 
    The last step is to determine which email that should recieve the message:

    PHP Code:
    if( isset($_POST['attention']) )
    {
      
    $attention strtolower($_POST['attention']);
      
    $email = isset($emails[$attention]) ? $emails[$attention] : false;
      
      if( 
    $email === false // the specified attention is invalid
        
    die('the selected attention is not valid...');
      
      
    // send the email here...

    This should give you a basic idea of how to do it.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SitePoint Evangelist
    Join Date
    May 2005
    Location
    Houston, Texas, USA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so much for your reply!! I pasted the php string, and got a result, but not the expected result. I'm sending myself email now. I'm not sure what to do with the second string, even though I'm sure it holds the key to the solution.

  4. #4
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Is it the array that's confusing you? Just place it at the top of your script.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  5. #5
    SitePoint Evangelist
    Join Date
    May 2005
    Location
    Houston, Texas, USA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I put it on the second line. The email goes to hi@... no matter which field in the contact form is selected. Again, thanks and remember I'm a programming dummie of the most extreme kind. Forgive my ignorance.

    <?php
    $myemail = "hi@hungryscafe.com";
    $emails = array(
    'Webmaster' => 'webmaster@hungryscafe.com',
    'Other' => 'sue@hungryscafe.com'
    );
    $ccx = "";
    if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
    {
    echo "<h2>Use Back - Enter valid e-mail</h2>\n";
    $badinput = "<h2>Feedback was NOT submitted</h2>\n";
    }
    if(empty($visitor) || empty($visitormail) || empty($notes )) {
    echo "<h2></h2>\n";
    }
    echo $badinput;

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

    $attn = $attn . "(" . $ccopy . ")" ;
    $subject = $attn;

    $notes = stripcslashes($notes);

    $message = " $todayis [EST] \n
    Attention: $attn \n
    Message: $notes \n
    From: $visitor ($visitormail)\n
    Additional Info : IP = $ip \n
    Browser Info: $httpagent \n
    Referral : $httpref \n
    ";

    $from = "From: $visitormail\r\n";

    if (($ccopy == "") && ($visitormail != ""))
    mail($visitormail, $subject, $message, $from);

    if ($myemail != "")
    mail($myemail, $subject, $message, $from);

    if ($ccx != "")
    mail($ccx, $subject, $message, $from);

    ?>
    <p align="center"> <?php echo $todayis ?></p>
    <p align="center"><br />
    <strong>Thank you,&nbsp;<span class="style77"><?php echo $visitormail ?> </span>for contacting our office. </strong><br />
    <br />
    <strong>Attention/strong> <?php echo $attn ?></p>
    <p align="center"><br />
    <strong>Message/strong><br />
    <span class="style77">
    <?php $notesout = str_replace("\r", "<br/>", $notes);
    echo $notesout; ?>
    <br />
    <?php

  6. #6
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Change the following two lines:

    PHP Code:
    if ($myemail != "")
    mail($myemail$subject$message$from); 
    ... to the following:

    PHP Code:
    mail($email$subject$message$from); 
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  7. #7
    SitePoint Evangelist
    Join Date
    May 2005
    Location
    Houston, Texas, USA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The change made the email go to the sender.

  8. #8
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You haven't added the code where the selected attention is used to determine which email the message should be sent to. I didn't see that before, and just assumed that the email was stored in $email.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  9. #9
    Are You There? KDesigns's Avatar
    Join Date
    Oct 2003
    Location
    Your Monitor
    Posts
    1,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I am understanding correctly, there is simply a drop-down field on the form needed that will determine where the mail is sent? Is this correct?

    If so, all you need to do is put the posted attention field as the eMail address to be mailed to:
    PHP Code:
    $mail_to $_POST['attn_field']; 
    If some of the fields need to be sent to one address while other fields sent to another, why don't you simply setup two separate messages in your form handler script? One message would contain the data from the fields that need to be sent to one while the other would be sent to the remainder?
    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!

  10. #10
    SitePoint Evangelist
    Join Date
    May 2005
    Location
    Houston, Texas, USA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it's time to go to school. What do you suggest I take first?

  11. #11
    Are You There? KDesigns's Avatar
    Join Date
    Oct 2003
    Location
    Your Monitor
    Posts
    1,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are wanting to learn PHP there's no need for 'school' per se. Go out and get a copy of PHP Bible. It's in a very easy format and helped me a lot when first learning the language. However, I'd be more than happy to help you get your current problem working though.
    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!

  12. #12
    SitePoint Evangelist
    Join Date
    May 2005
    Location
    Houston, Texas, USA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This seems like the easiest thing to do, but I am ill equipped, as you can see from the first person who tried to help. If this were a paying job I'd go out and get a real programmer like one of you! Go to http://hungryscafe.com/contact.php to see my problem in full. The "customer" has asked me to send:

    Technical Support and General Support to hi@hungryscafe.com

    and

    Sales and Webmaster to webmaster@hungryscafe.com.

    You are all so kind to help--I'm so new to this. I've only been putting pages together for about 6 months. My strength is obviously not on the programming side!

  13. #13
    SitePoint Evangelist
    Join Date
    May 2005
    Location
    Houston, Texas, USA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SHould I get the regular PHP bible published in 2002 or mysql with PHP5? I guess the latter being more recent...

  14. #14
    Are You There? KDesigns's Avatar
    Join Date
    Oct 2003
    Location
    Your Monitor
    Posts
    1,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The latter would be the best probably but it would be a wise idea to learn PHP 4.x as well because most servers are not upgraded to PHP 5 as of yet.
    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!

  15. #15
    Are You There? KDesigns's Avatar
    Join Date
    Oct 2003
    Location
    Your Monitor
    Posts
    1,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very easy to do what you need...

    The easiest way is to put the eMail address as the value of the option field but then you run the risk of spam crawlers scraping it from the code.

    The best way to do it is check for the value and set the eMail accordingly. The default in the switch is the value that will be set if no option is selected. You will also need to get rid of the whitespace before the first and last characters of the values in your options for the below code to function. The case represents the value pased from that option.
    PHP Code:
    $mail_to $_POST['attn'];

    switch(
    $mail_to) {
         case 
    'Technical Support':
            
    $mail_to 'techsupport@domain.com';
            break;
         case 
    'General Support':
            
    $mail_to 'general@domain.com';
            break;
         case 
    'Webmaster':
            
    $mail_to 'webmaster@domain.com';
            break;
         case 
    'Sales':
            
    $mail_to 'sales@domain.com';
            break;
         default:
            
    $mail_to 'info@domain.com';
            break;

    You will then just use the $mail_to variable as your to address in mail().
    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!

  16. #16
    Are You There? KDesigns's Avatar
    Join Date
    Oct 2003
    Location
    Your Monitor
    Posts
    1,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    very nice design by the way!
    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!

  17. #17
    SitePoint Evangelist
    Join Date
    May 2005
    Location
    Houston, Texas, USA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice of you to comment on my design, especially coming from a designer. THe client liked it but I didn't believe them. It has its redeeming qualities...

    I tried the code. There is a change-- now I get two identical emails, but both sent to hi@... So if I select Webmaster, I get 2 emails sent to hi@... What have I done wrong? I'm ordering the bible today.

  18. #18
    Are You There? KDesigns's Avatar
    Join Date
    Oct 2003
    Location
    Your Monitor
    Posts
    1,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post the code as it is now so I can get a better look?

    As far as the design... it has a very clean modern look to it which I love. The only thing I would suggest is maybe adding something to the homepage to set it apart from the rest of the site. Nothing dramatic, but you could keep the same 'square' image theme that you've got going at the top and create a shape built out of say 5 or 7 squares. Below is something I threw together to give you an idea of what I mean (keep in mind I did this in about 10 minutes so it's not perfect)

    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!

  19. #19
    SitePoint Evangelist
    Join Date
    May 2005
    Location
    Houston, Texas, USA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is wonderful!!! I will do something about it. You are so right.

  20. #20
    SitePoint Evangelist
    Join Date
    May 2005
    Location
    Houston, Texas, USA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry I didn't see the first part. I liked your idea so much that I forgot what we were originally doing here. lol

    <?php

    $myemail = "hi@hungryscafe.com";
    $ccx = "";
    if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
    {
    $mail_to = $_POST['attn'];

    switch($mail_to) {
    case 'Technical Support':
    $mail_to = 'hi@hungryscafe.com';
    break;
    case 'General Support':
    $mail_to = 'hi@hungryscafe.com';
    break;
    case 'Webmaster':
    $mail_to = 'webmaster@hungryscafe.com';
    break;
    case 'Sales':
    $mail_to = 'jcs@hungryscafe.com';
    break;
    default:
    $mail_to = 'hi@hungryscafe.com';
    break;
    }
    echo "<h2>Use Back - Enter valid e-mail</h2>\n";
    $badinput = "<h2>Feedback was NOT submitted</h2>\n";
    }
    if(empty($visitor) || empty($visitormail) || empty($notes )) {
    echo "<h2></h2>\n";
    }
    echo $badinput;

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

    $attn = $attn . "(" . $ccopy . ")" ;
    $subject = $attn;

    $notes = stripcslashes($notes);

    $message = " $todayis [EST] \n
    Attention: $attn \n
    Message: $notes \n
    From: $visitor ($visitormail)\n
    Additional Info : IP = $ip \n
    Browser Info: $httpagent \n
    Referral : $httpref \n
    ";

    $from = "From: $visitormail\r\n";

    if (($ccopy == "") && ($visitormail != ""))
    mail($visitormail, $subject, $message, $from);

    if ($myemail != "")
    mail($myemail, $subject, $message, $from);

    if ($ccx != "")
    mail($ccx, $subject, $message, $from);

    ?>
    <p align="center"> <?php echo $todayis ?></p>
    <p align="center"><br />
    <strong>Thank you,&nbsp;<span class="style77"><?php echo $visitormail ?> </span>for contacting our office. </strong><br />
    <br />
    <strong>Attention/strong> <?php echo $attn ?></p>
    <p align="center"><br />
    <strong>Message/strong><br />
    <span class="style77">
    <?php $notesout = str_replace("\r", "<br/>", $notes);
    echo $notesout; ?>
    <br />
    <?php echo $ip ?>

  21. #21
    Are You There? KDesigns's Avatar
    Join Date
    Oct 2003
    Location
    Your Monitor
    Posts
    1,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, going through all of that was a bit 'jumbled' so I wrote a controller for you. I've pasted it below but I'm sure the spacing will be thrown off. If you want the actual file just send me an eMail I'll send it to you. You can just click my username and a drop-down list will come with a link to eMail me.

    You will need to add a textfield to your contact form so the visitor can type in their name. The field name should be 'visitor'.
    PHP Code:
    <?php
    $ip 
    $_POST['ip'];
    $httpref $_POST['httpref'];
    $httpagent $_POST['httpagent'];

    $visitor $_POST['visitor'];
    $visitormail $_POST['visitormail'];
    $ccopy $_POST['ccopy'];

    $attn $_POST['attn'];

    $notes stripcslashes($_POST['notes']);


    if(!
    $visitormail || !$notes || !$visitor) {
        
    //if visitor, visitormail or notes fields were left blank
        
    echo "<h1>Use Back:  Please enter all information</h1> \n";
    }
    else {
        
    //Decide where eMail should go
        
    switch($attn) {
            case 
    'Technical Support':
                
    $mail_to 'hi@hungryscafe.com';
                break;
            case 
    'General Support':
                
    $mail_to 'hi@hungryscafe.com';
                break;
            case 
    'Webmaster':
                
    $mail_to 'webmaster@hungryscafe.com';
                break;
            case 
    'Sales':
                
    $mail_to 'jcs@hungryscafe.com';
                break;
            default:
                
    $mail_to 'hi@hungryscafe.com';
                break;
        }

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

        
    //eMail Subject
        
    $subject $attn;

        
    //eMail Message
        
    $message "
        
    $todayis [EST]

        Attention: 
    $attn
        Message: 
    $notes
        From: 
    $visitor ($visitormail)
        
        Additional Info: 
            IP: 
    $ip
            Browser: 
    $httpagent
            Referral: 
    $httpref";

        
    //eMail From
        
    $from "From: $visitor <$visitoremail>";

        
    //Mail Form

        
    if($ccopy) {
            
    //If CCopy was selected add visitor email
            
    $mail_to "$mail_to$visitormail";

            
    $send_form mail($mail_to$subject$message$from);
        }
        else {
            
    //ccopy was not selected
            
    $send_form mail($mail_to$subject$message$from);
        }

        
    //If form was sent echo thank you message
        
    if($send_form) {
            
    ?>
            <p align="center"> <?php echo $todayis ?></p>
            <p align="center"><br />
            <strong>Thank you,&nbsp;<span class="style77"><?php echo $visitor ?> </span>for contacting our office. </strong><br />
            <br />
            <strong>Attention:</strong> <?php echo $attn ?></p>
            <p align="center"><br />
            <strong>Message:</strong><br />
            <span class="style77">
            <?php $notesout str_replace("\r""<br/>"$notes);
            echo 
    $notesout?>
            <br />
            <?php echo $ip ?>
        <?php
        
    }
        else {
            echo 
    "<p>We are sorry but there was a problem sending your information.  Please try again.</p>";
        }
    }
    ?>
    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!

  22. #22
    SitePoint Evangelist
    Join Date
    May 2005
    Location
    Houston, Texas, USA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried this script. No matter what fields were filled in (all) in the contact form, I got an error message: Use Back: Please enter all information.

    I don't want you to do any more I feel quilty. I'm going to get the bible. I will let you know when I figure this out. I'm sure you have given me perfectly wonderful stuff to work with that may even need just one minor tweak, but I'm clueless. I will let you know when I have a clue.

    Oh, I moved the images around: http://www.hungryscafe.com/Copy%20of%20index.html


    Thank you !! And have a great day!! Especially on the beach. I grew up on one too it's the best way!

  23. #23
    SitePoint Evangelist
    Join Date
    May 2005
    Location
    Houston, Texas, USA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    750am CST. Okay, I changed a couple things (like the error message part) and I got it to work. It's not working exactly like I had intended, BUT IT'S WORKING!!! I'm gettin the bible... Thank you so much!!!!!

  24. #24
    Are You There? KDesigns's Avatar
    Join Date
    Oct 2003
    Location
    Your Monitor
    Posts
    1,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your are more than welcome!

    The reason it wouldn't work with the script I did is because you didn't add a visitor text field to the contact form. You want to be able to display their name in your message but have given no way for that info to be added.

    If you add the following to your Contact Form the script I pasted will work without a hitch
    Code:
    Name: <input type='text' name='visitor' id='visitor'>
    If you don't want to add the field you can simply change this
    PHP Code:
    if(!$visitormail || !$notes || !$visitor) { 
    to this
    PHP Code:
    if(!$visitormail || !$notes) { 
    and it will work as well.
    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!

  25. #25
    SitePoint Member
    Join Date
    May 2005
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Follow-up on contact script

    Hello KDESIGNS!
    I can do a little PERL and in searching for a contact script I found this thread. This is pretty much the approach I wanted to develop. While I've looked at php a time or two, and tested my host's installation, etc. -- thing is, whereas in PERL the script is in a protected directory, I don't see how this php script is protected, that is, how the "embedded" eMail addresses are kept from public access.
    If you find it not too inconvenient, wouldst thou post a hint or two on this?
    thx
    mike


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
  •