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

Thread: email encrypted in form

  1. #1
    Join Date
    Dec 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default email encrypted in form

    hello guys, I'm not a programmer but I need some help with a form.

    1) imagine to have a few names, like Jack, Frank, Mary. To each name an email address is assigned (but it's not visible)

    2) next to the list of names there's a form with fields "send to", "your email" and "your message"

    3) when the user clicks on a name, its corresponding email address appears in the "send to" field, and once submit button is pressed the message is sent to that person.

    Hope someone can spare a couple of minute and write this little script for me... Thank you. Criss

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

    Default

    A much better idea would be to just have a reference to their name, then on the server side script which interprets it send to the corresponding email. "Jack" becomes "Jack@your.com", and the visitor never knows the real address, nor do spambots.
    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
    Dec 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    yes, a reference like "manager, supervisor," etc.. and this title could appear in the "send to" box, instead of an email....

    but my problem is that I have no idea how to write such a script anyway. Can you help writing a few lines for me?

  4. #4
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    if you only have a couple of people you could use radio buttons

    Code:
    <form name="frmEmail" action="sendEmail.php" method="post">
        <label>
              <span>Receipient:</span>
               <input type="radio" name="ureceipient" value="jack"> Jack
              <input type="radio" name="ureceipient" value="frank"> Frank
              <input type="radio" name="ureceipient" value="mary"> Mary
         </label>
         <label>
               <span>Message:</span>
               <textarea cols="10" rows="5" name="ucomment"></textarea>
         </label>
         <input type="submit" name="sumbit" value="Send Email">
    </fieldset>
    </form>
    if you would prefer a drop down you can do
    Code:
    <form name="frmEmail" action="sendEmail.php" method="post">
        <label>
              <span>Receipient:</span>
               <select name="ureceipient">
                   <option value="jack">Jack</option>
                   <option value="frank">Frank</option>
                   <option  value="mary">Mary</option>
              </select>
         </label>
         <label>
               <span>Message:</span>
               <textarea cols="10" rows="5" name="ucomment"></textarea>
         </label>
         <input type="submit" name="sumbit" value="Send Email">
    </fieldset>
    </form>
    and sendEmail.php would look like
    PHP Code:
    <?php
    // Define the email addresses for the specific names
    $to = array(
         
    "jack" => "jack@domain.com",
         
    "frank" => "frank@domain.com",
         
    "mary" => "mary@domain.com"
    );
    // Populate the email "to" field
    $receipient $to[$_POST['ureceipient']];

    // Send Email
    mail($receipient,'Subject','Message');
    ?>
    if you wanted to send to multiple people at the same time, then that is doable too, just let us know and a script will be given. if you have any questions just ask, sorry for the very rough example

  5. #5
    Join Date
    Dec 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks a lot for taking your time in helping me...
    I actually don't need radio buttons or drop menu either. Have a look at www.arsenalemusica.eu/staff.php and I think you'll understand what I need..i think it''s an easy one, but I have no idea how to build it

    Criss

  6. #6
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    edited from boogyman's post

    HTML Code:
    <form name="frmEmail" action="sendEmail.php" method="post">
              <span>Receipient:</span>
               <input type="text" name="ureceipient" value="Enter Name" /> 
               <span>Message:</span>
               <textarea cols="10" rows="5" name="ucomment">Enter Message</textarea>
         </label>
         <input type="submit" name="submit" value="Send Email">
    </fieldset>
    </form>
    sendEmail.php:
    PHP Code:
    <?php
    // Define the email addresses for the specific names
    $to = array(
         
    "jack" => "jack@domain.com",
         
    "frank" => "frank@domain.com",
         
    "mary" => "mary@domain.com"
    );
    // Populate the email "to" field
    $receipient $to[$_POST['ureceipient']];
    if (
    $receipient != null) {
    // Send Email
    mail($receipient,'Subject','Message');
    } else {
    echo 
    "Not a valid name. Please go back and try again";
    }
    ?>
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  7. #7
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Or with links:

    HTML Code:
    <a href="sendEmail.php?contact=jac">Jack</a>
    <a href="sendEmail.php?contact=mary">Mary</a>
    <a href="sendEmail.php?contact=frank">Frank</a>
    sendEmail.php:
    PHP Code:
    <?php
    // Define the email addresses for the specific names
    $to = array(
         
    "jack" => "jack@domain.com",
         
    "frank" => "frank@domain.com",
         
    "mary" => "mary@domain.com"
    );
    // Populate the email "to" field and hide the notice error when using E_ALL as the error reporting
    $receipient = @$to[$_GET['contact']];
    if (
    $receipient != null) {
    // Send Email
    mail($receipient,'Subject','Message');
    } else {
    echo 
    "Not a valid name. Please go back and try again";
    }
    ?>
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  8. #8
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Its generally not advisable to have them insert a name, without giving them options because they could misspell it, they could try to send to a name not in the directory, or other errors could crop up...
    The only way to get around something like this would be to use a switch loop and assign a default email address incase one of those or another error did occur.

    PHP Code:
    $to strtolower($_POST['ureceipient']);
    $to = switch($to)
    {
         case 
    jack
               
    'jack@domain.com'
               
    break;
         case 
    frank:
               
    'frank@domain.com'
               
    break;
         case 
    mary:
         default:
               
    'mary@domain.com'
               
    break;

    Using links would be a fine, but you would need server-side support to capture the rest of the values inputted before the link is clicked, thus not really making it not the best idea in my mind

  9. #9
    Join Date
    Dec 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your patience and help so far guys, it seems we're getting there. But before I go ahead I have some doubts (I'm a beginner with php).

    The two php files' tasks are:
    1) choose the name and insert it in the "send to" field
    2) pick up the assigned email address and send

    I understand that using links might not be the best option, but actually the idea behind it is correct, as the user will need to click on the name/occupation to trigger the form into a "ready-to-launch" state. If a name is not clicked the form cannot be sent.

    The "switch loop" method is the best option, but how would it read from file 1 if links are not advisable? In other words, if I cannot use <a href="sendEmail.php?contact=jack">Jack</a>, what html can I use in file 1 ?

    Then, to summarize, I reckon file 2 should be like this:
    PHP Code:
    <?php
    // Define the email addresses for the specific names
    $to strtolower($_POST['ureceipient']);
    $to = switch($to)
    {
         case 
    jack
               
    'jack@domain.com'
               
    break;
         case 
    general manager
               
    'jack@domain.com'
               
    break;
         case 
    frank:
               
    'frank@domain.com'
               
    break;
         case 
    technical director:
               
    'frank@domain.com'
               
    break;
         case 
    mary:
         default:
               
    'mary@domain.com'
               
    break;
    }  

    // Populate the email "to" field
    $receipient $to[$_POST['ureceipient']]; 
    if (
    $receipient != null) { 
    // Send Email 
    mail($receipient,'Subject','Message'); 
    } else { 
    echo 
    "you did not choose a name"

    ?>

  10. #10
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by stardom View Post
    1) choose the name and insert it in the "send to" field
    2) pick up the assigned email address and send

    I understand that using links might not be the best option, but actually the idea behind it is correct, as the user will need to click on the name/occupation to trigger the form into a "ready-to-launch" state. If a name is not clicked the form cannot be sent.
    this is something very achievable. using links throughout the site the user could click on the link to get to the contact form page, the contact would then be populated into the "To:" field automatically, which would solve that dilemma.


    The "switch loop" method is the best option, but how would it read from file 1 if links are not advisable? In other words, if I cannot use <a href="sendEmail.php?contact=jack">Jack</a>, what html can I use in file 1 ?
    I am not really following you at all here? can you restate?


    Then, to summarize, I reckon file 2 should be like this:
    PHP Code:
    <?php
    // Define the email addresses for the specific names
    $to strtolower($_POST['ureceipient']);
    $to = switch($to)
    {
         case 
    jack
               
    'jack@domain.com'
               
    break;
         case 
    general manager
               
    'jack@domain.com'
               
    break;
         case 
    frank:
               
    'frank@domain.com'
               
    break;
         case 
    technical director:
               
    'frank@domain.com'
               
    break;
         case 
    mary:
         default:
               
    'mary@domain.com'
               
    break;
    }

    One advantage of the switch loop is that you can assign multiple values to 1 sequence. so where you have.
    case frank:
    'frank@domain.com'
    break;
    case technical director:
    'frank@domain.com'
    break;
    it could reduced to

    Code:
         case frank:
         case technical director:
               'frank@domain.com'
               break;
    The loops will attempt to find the appropriate "person" in this case being either frank or technical director and continue on until it finds some value / break...
    That is a very crude and probably not very helpful definition, but take a look at http://us2.php.net/switch for a better explanation...

    The default at the very bottom is for values that are not found under any of the other conditions, ... basically its a "catch-all".

    The problem I see with this is that if someone wanted the Technical Director Frank, they could it in wrong and what is submitted is "Tech Director" or "tehc writer" or something along those lines. This is why its really not advised to have them enter in a "name" persay, but an email address, and if they dont have an email address, then providing them a list of person(s) in the form of a drop down or a check box or radio boxes.

    PHP Code:
    if ($receipient != null) { 
    // Send Email 
    mail($receipient,'Subject','Message'); 
    } else { 
    echo 
    "you did not choose a name"

    ?> 
    this will never be false because of the default switch loop value.
    also the email address is not the only thing that would cause the email to not be sent, so something that I think would be more appropriate would be

    PHP Code:
    if( !mail($to'Subject''Message') )
    {
         echo 
    "ERROR MESSAGE";
    }
    else
    {
         echo 
    "THANK YOU EMAIL MESSAGE";


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
  •