Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jul 2006
    Posts
    168
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Email Setup and send to multiple people chosen in form

    I have a form designed that people complete, and can choose who they want the results to be emailed to. I think I have the script written correctly (for the most part) so it would work, but am not sure how to get the names you select from the drop down list, into the recipients. Do I need to set up a field in the DB to accomodate these. If so, can I have all the names go in one field, seperated by a comma, as there could be 15 - 20 names.

    When developing the mail script, and working on the "FROM" section, does it have to be a valid email address, or can it just be a name? I have a query written to get the email address, but I am having troubles getting it to work, because of where I need to put quotation marks, etc., it doesn't like it.

    any suggestions, what I have is below.

    PHP Code:
    //Assign the Headers
    $headers "FROM:" mysql_query(Select Email from employees WHERE Name='$tech')"\r\n";
    $subject "Subject: Work Order Number ".$_POST['Work']." has been submitted\r\n";
    $headers "Content-Type: text/plain;\r\n charset=iso-8859-1\r\n";
    $recipients "";
    $body "Work Order Number".$_POST['Work'];
            
    "Technician:".$_POST['Tech'];
            
    "Site:".$_POST['Site'];
            
    "Description of Problem:".$_POST['Issue'];
            
    "Possible Resolution:".$_POST['Resolve'];
            
    "Assistance Required:".$_POST['Assist'];
            
    "Level of Severity:".$_POST['Severe'];
            
    "The Complete Work Order can be viewed by visiting http://www.xxx.ca/GE/index.htm";

    //Mail the Notification to recipients
    mail($from$recipients$body$headers); 
    Ken

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    If it were me, I'd normalize the database by creating a new table for the email addresses and link it with a foreign key. Then I'd build the $recipients variable with a foreach loop.

  • #3
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post
    No database is needed for omething like this. there are two ways of doing it, one would be too add a drop down box and set the values to be the email address, as such:

    Code:
    <select size="1" name="to">
    			<option value="admin@mysite.com">Admin</option>
    			<option value="webmaster@mysite.com">Webmaster</option>
    </select>
    then in your PHP code you would do this:

    PHP Code:
    $recipients $_POST['to']; 
    Only thing about this is that a bot could index that page and spam those email address. An alternitive would be to store the emails in the php code like so:

    form
    Code:
    <select size="1" name="to">
    			<option value="admin">Admin</option>
    			<option value="webmaster">Webmaster</option>
    </select>
    php
    PHP Code:
    $recipients $_POST['to'];
    if (
    $recipients == "admin") {
    $recipients "admin@mysite.com";
    } else if (
    $recipients =="webmaser") {
    $recipients "webmaster@mysite.com";

    As for the from header im not sure, only way to find out for shore is to try it. I think i answerd what your looking for, if not let me know

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Oh and by the way you are not understanding how queries work if you think that imbedding a call to the mysql_query() function in a variable assignment will work. Maybe this will help:

    HOW TO PERFORM A QUERY

    Step 1: Connect to the database (I assume you have this working fine)
    Step 2: Perform the query using the mysql_query() function
    This function requires a string containing your query text.
    This function returns a resource on success, "false" on failure. A resource is a special variable, holding a reference to an external resource.

    Step 3: Fetch data from your query's resource using one of the following functions:
    mysql_fetch_array
    mysql_fetch_assoc
    mysql_fetch_row
    mysql_result

    There are more, but those are the main fetchers.

    Can you see how you are misusing mysql_query() now?

  • #5
    Regular Coder
    Join Date
    Jul 2006
    Posts
    168
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi There

    thanks for the input, it is appreciated. I was trying to follow this through from a book I have, but have possibly misread how it works.

    1. The people these people would be choosing to email to would be employees, hence they could change and this is why they are in a DB. The employee table is a separate table from the one where the rest of the form results go to.

    2. I am getting the idea for the query's, but one question. If the form where the data is inputted, example tech name, work order #, etc., is the same form where the email is being generated from, would it still not work the way I have it set up. I am questioning this because i just reread the section from Beginning PHP5 and MySQL. Again, since the form being completed, and the email are the same, would the $_POST[] work, or will I need to have it stored in the DB first, then generate an email as a seperate step.

    It is also my understanding that by using \n\r will reduce the chances of spam email and BOTS getting the addresses. Is this true? Is it also safer to keep the email addresses out of the actual script and have them pulled from a DB?

    I guess it is back to the drawing board for this portion of the form.

    Thanks for the input

    Ken

  • #6
    Regular Coder
    Join Date
    Jul 2004
    Posts
    201
    Thanks
    8
    Thanked 1 Time in 1 Post
    its not "safer" to get them from the database rather straight from your php file, infact it wouldnt make any difference saftey wise. As long as they are not on the main form itself then the bots wont be able to get the email address. Although there are some bots that can fill in the form and submit it, theres a topic on this just recently, you might want to read it for some solutions against this.


  •  

    Posting Permissions

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