Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Having option of email recipient in form mail ?

  1. #1
    Join Date
    Jul 2007
    Location
    New Zealand
    Posts
    81
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Having option of email recipient in form mail ?

    Hi there,

    I have a script I acquired from another site and it works fine, but I would like to have the option to let the user choose whether they send the email to the artist or the webmistress by either selecting from a drop down option or checking a box or radio button.

    Is it possible to do this? Currently, all mail goes to both of us, but for the artist's privacy, I would like them to have their own email that goes exclusively to them and one for the webmistress. Does that make sense?

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Well, it's very possible. But the code would need to be changed so it does that. Send the dropdown value as the email for the to parameter of the mail() function. But we have no idea how the script works beyond such guesses without you actually posting at least part of the code.

    If you can't/won't, then all I can say is that you could setup two separate forms, or submit to two different pages based on the dropdown menu.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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

    Default

    You would need to post the code for us to modify it, but it is definitely possible. If you look through a few threads in this section, you will find some scripts that actually fit your needs.

    Hope this helps.

    Edit:
    Sorry dj, cross posted.
    "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
    Jul 2007
    Location
    New Zealand
    Posts
    81
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default

    Thanks for your quick replies!

    // $mailto - set to the email address you want the form
    // sent to, eg
    //$mailto = "someone@somewhere.com" ;

    $mailto = 'someone@somewhere.com';

    // $subject - set to the Subject line of the email, eg
    //$subject = "Feedback Form" ;

    $subject = "Website Enquiry" ;

    $formurl = "http://www.example.com/feedback.html" ;
    $errorurl = "http://www.example.com/error.html" ;
    $thankyouurl = "http://www.example.com/thankyou.html" ;

    $uself = 0;

    // -------------------- END OF CONFIGURABLE SECTION ---------------

    $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
    $name = $_POST['name'] ;
    $fromemail = "From: someone@somewhere.com";
    $email = $_POST['email'] ;
    $comments = $_POST['comments'] ;
    $http_referrer = getenv( "HTTP_REFERER" );

    if (!isset($_POST['email'])) {
    header( "Location: $formurl" );
    exit ;
    }
    if (empty($name) || empty($email) || empty($comments)) {
    header( "Location: $errorurl" );
    exit ;
    }
    if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
    header( "Location: $errorurl" );
    exit ;
    }

    if (get_magic_quotes_gpc()) {
    $comments = stripslashes( $comments );
    }

    $messageproper =

    "This message was sent from:\n" .
    "$http_referrer\n" .
    "------------------------------------------------------------\n" .
    "Name of sender: $name\n" .
    "Email of sender: $email\n" .
    "------------------------- COMMENTS -------------------------\n\n" .
    $comments .
    "\n\n------------------------------------------------------------\n" ;

    mail($mailto, $subject, $messageproper,
    "$fromemail", $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.08" );
    header( "Location: $thankyouurl" );
    exit ;

    ?>
    This is the .php I've altered the email address it's going to so the bots don't grab it


    <form action="http://www.ravenouspathogen.com/contact.php" method="post">
    <table border="0" bgcolor="#000000" cellspacing="5">
    <tr><td><font face="garamond">Name:</td><td><input type="text" size="30" name="name"></td></tr>
    <tr><td><font face="garamond">Email address:</td><td><input type="text" size="30" name="email"></td></tr>
    <tr><td valign="top"><font face="garamond">Enquiry:</td><td><textarea name="comments" rows="10" cols="40"></textarea></td></tr>
    <tr><td>&nbsp;</td><td><input type="submit" value="Send" style="color: black; font-family: verdana; font-size: 10pt; font-weight: bold; background-color: white;" class="send"></td></tr>
    </table>
    </form>
    And that's the actual form script on the html page.
    On the form, it should simply be a case of:
    Select Email Recipient
    <input type="radio" name="emailto" value="artist"> Artist
    <br>
    <input type="radio" name="emailto" value="webmistress"> Webmistress
    Or something like that, right? I've never in my life used radio buttons - never had a need to, so maybe I'm a little out. But then there's still the matter of modifying the php to get it to send it where it's meant to go.

    I had a look through the forum for an answer to my question, but the closest thing I came to was a javascript fix.
    Last edited by djr33; 09-04-2008 at 02:18 AM.

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    $mailto is set near the top of the page. Set that to the value of your dropdown.
    Or, use a number for that dropdown value, 0 and 1.
    Then just use if ($_POST['dropdownname']===1) { $mailto = 'what@ever.1'; } else { $mailto = 'an@other.2'; }
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Jul 2007
    Location
    New Zealand
    Posts
    81
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default

    Okay, I have the drop down box, but for some reason I'm not understanding what you mean about setting the option value to the dropdown in the $mailto section of the script at the top.
    I tried $mailto = 'someone@somewhere.com', 'someoneelse@somewhere.com'

    and then I tried $mail to = 'recipient'

    followed by the bit of code further down in the isset and made it reflect the email addresses, but I it's coming up with parse errors saying something was identical and expecting '/' or and I KNOW I didn't quite understand what you meant, but tried many variables to see if I could figure it out. I also looked on the web.

    A couple of years ago I bought a book with the intention in mind of learning php and learning to do my own scripts and got busy and the book got sold. I wish I had it now as I'm sure what you're telling me is fairly straight forward, but I'm not quite getting it.

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

    Default

    Try this:

    contact.html:
    Code:
    <form action="contact.php" method="post">
    <table border="0" bgcolor="#000000" cellspacing="5">
     <tr>
      <td>Send To:</td>
      <td>
       <select name="mailto">
        <option value="test@test.com">Test Name 1</option>
        <option value="test2@test.com">Test Name 2</option>
       </select>
      </td>
     </tr>
     <tr>
      <td><font face="garamond">Name:</td>
      <td><input type="text" size="30" name="name"></td>
     </tr>
     <tr>
      <td><font face="garamond">Email address:</td>
      <td><input type="text" size="30" name="email"></td>
     </tr>
     <tr>
      <td valign="top"><font face="garamond">Enquiry:</td>
      <td><textarea name="comments" rows="10" cols="40"></textarea></td>
     </tr>
     <tr>
      <td>&nbsp;</td>
      <td><input type="submit" value="Send" style="color: black; font-family: verdana; font-size: 10pt; font-weight: bold; background-color: white;" class="send"></td>
     </tr>
    </table>
    </form>
    then, contact.php:

    Code:
    <?php
    
    $mailto = $_POST['mailto'];
    
    // $subject - set to the Subject line of the email, eg
    //$subject = "Feedback Form" ;
    
    $subject = "Website Enquiry" ;
    
    $formurl = "http://www.example.com/feedback.html" ;
    $errorurl = "http://www.example.com/error.html" ;
    $thankyouurl = "http://www.example.com/thankyou.html" ;
    
    $uself = 0;
    
    // -------------------- END OF CONFIGURABLE SECTION ---------------
    
    $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
    $name = $_POST['name'] ;
    $fromemail = "From: someone@somewhere.com";
    $email = $_POST['email'] ;
    $comments = $_POST['comments'] ;
    $http_referrer = getenv( "HTTP_REFERER" );
    
    if (!isset($_POST['email'])) {
    header( "Location: $formurl" );
    exit ;
    }
    if (empty($name) || empty($email) || empty($comments)) {
    header( "Location: $errorurl" );
    exit ;
    }
    if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
    header( "Location: $errorurl" );
    exit ;
    }
    
    if (get_magic_quotes_gpc()) {
    $comments = stripslashes( $comments );
    }
    
    $messageproper =
    
    "This message was sent from:\n" .
    "$http_referrer\n" .
    "------------------------------------------------------------\n" .
    "Name of sender: $name\n" .
    "Email of sender: $email\n" .
    "------------------------- COMMENTS -------------------------\n\n" .
    $comments .
    "\n\n------------------------------------------------------------\n" ;
    
    mail($mailto, $subject, $messageproper,
    "$fromemail", $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.08" );
    header( "Location: $thankyouurl" );
    exit ;
    
    ?>
    Hope this helps.
    Last edited by djr33; 09-04-2008 at 02:18 AM.
    "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

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I would recommend the code highlighted in my post. Just put it where Blizzard's code is in the script.

    That would work as well, but in doing so, you open yourself up to be a spam server. Anyone can submit a similar form from their website, or using Javascript, and send to any email they would like.

    Alternatively, you could check if the email of $_POST['mailto'] is in an allowed list, but just using a number is:
    1. easier
    2. prevents people from finding and harvesting your emails in the form, if that appeals to you
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Jul 2007
    Location
    New Zealand
    Posts
    81
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default

    Parse error: syntax error, unexpected T_IS_IDENTICAL, expecting ',' or ')' in /home/www/ravenouspathogen.com/contact.php on line 79

    To see what I'm doing wrong:
    $mailto = $_POST['mailto'];

    $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
    $name = $_POST['name'] ;
    $fromemail = "From: info@someplace.com";
    $email = $_POST['email'] ;
    $comments = $_POST['comments'] ;
    $http_referrer = getenv( "HTTP_REFERER" );

    if (!isset($_POST['mailto']===1) { $mailto = 'info@someplace.com'; } else { $mailto = 'webmistress@someplace.com'; }

    <tr><td><font face="garamond">Select Recipient:</font></td><td><select name="mailto" size="1">
    <option value="1">Artist</option>
    <option value="2">Webmistress</option>
    </select></td></tr>
    I even tried it without the 'isset' - but that just messes things up. At one stage it came up with a syntax error unexpected }

    What is so blindingly obvious that I am missing?

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Haha. Yes, you are missing my typo.

    if (!isset($_POST['mailto'])===1) { $mailto = 'info@someplace.com'; } else { $mailto = 'webmistress@someplace.com'; }
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •