SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict trigger's Avatar
    Join Date
    Jun 2003
    Location
    Eagan
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    wierd looping in the mail script

    Does anyone know why this would print out a message twice? I have a form whose action is this script, and there are two arrays in it, customerEmail and emailTo. When you select a emailTo person, to email the $message to, it emails that person once, but shows the message twice.

    PHP Code:
    if ($contactName == 'None'){
            
    $contact $contactOther;
        }
        else if (
    $contactName != 'None'){
            
    $contact $contactName;
        }
    require_once(
    '../Connections/Connection.php');
    mysql_select_db($database_Connection$Connection);
    $now date('m-d-Y H:i');
    if (
    $status == 'Open'){
        
    $sqlquery "UPDATE tickets set ticketOwner='$ticketOwner', problemWith='$problem', issue='$issue', fix='$fix', 
        WHERE ticketKey='
    $ticketKey'" or die(mysql_error());
    }
    else if (
    $status == 'Closed'){
        
    $sqlquery"UPDATE tickets set timeClosed='$now', ticketOwner='$ticketOwner', status='$status', problemWith='$problem', issue='$issue', fix='$fix'
        WHERE ticketKey='
    $ticketKey'" or die(mysql_error());
    }
    $results mysql_query($sqlquery);
    foreach (
    $emailTo as $value){
        
    $message .= "Company Name: $companyName \n";
        
    $message .= "Contact: $contact \n";
        
    $message .= "Site Name: $siteName \n";
        
    $message .= "Contact Person's Phone Number: $PhoneNumber \n";
        
    $message .= "Support Level: $supportType \n";
        
    $message .= "Expiration Date of Support: $supportExpires \n";
        
    $message .= "Sales Representative: $salesRep \n";
        
    $message .= "Problem With: $problem \n";
        
    $message .= "Description of Problem: $issue \n";
        
    $message .= "Fix: $fix \n";
        
    mail($value 'Support Ticket Edited: ' .$ticketKey': ' .$problem$message);
    }
    foreach (
    $customerEmail as $value){
        
    $message .= "Company Name: $companyName \n";
        
    $message .= "Contact: $contact \n";
        
    $message .= "Site Name: $siteName \n";
        
    $message .= "Contact Person's Phone Number: $PhoneNumber \n";
        
    $message .= "Support Level: $supportType \n";
        
    $message .= "Expiration Date of Support: $supportExpires \n";
        
    $message .= "Sales Representative: $salesRep \n";
        
    $message .= "Problem With: $problem \n";
        
    $message .= "Description of Problem: $issue \n";
        
    $message .= "Fix: $fix \n";
        
    mail($value 'Support Ticket Edited: ' .$ticketKey': ' .$problem $message);
    }
    $success "1";
    header "Location: http://xxxxxxxxxxx.php"); 

  2. #2
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is success returned to another script?

  3. #3
    SitePoint Addict trigger's Avatar
    Join Date
    Jun 2003
    Location
    Eagan
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you mean $success? That field is put in there for later use, but doesn't really serve a purpose. The header function is working fine, and going to the page I've indicated, showing to me that its run through. Do you think the problem could be the $success variable?

  4. #4
    public static void brain Gybbyl's Avatar
    Join Date
    Jun 2002
    Location
    Montana, USA
    Posts
    647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all, it looks like you are relying on the fact that register_globals is turned on -- In most scenarious, this is not the case. You should be accessing your form fields with $_POST['name'] instead of $name.

    Secondly, you are using a foreach loop to send your email, and since you claim that it's printing twice, it probably means that there are two elements in the arrays you are traversing (or 1 element, if you count 0). Your best bet may be to get rid of the foreach() loop and just take the statements inside of the loop and try them standalone (you are trying to send only one email, right?)
    Ryan

  5. #5
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No but the way I read it the foreach loop is being run anyway I think it might work better with a while loop or possible an if statement that a foreach because A foreach loop means it will run (this means both of them)

    because they are not contained within any sort of condition so both are being run.

    Try restructing it so only one is run depending on your condition.

    You can also have bcc cc and maultipul address entered into the mail function up to you how they get their though

    (hope you could understand that explination its late here in australia after a long days work)

  6. #6
    SitePoint Addict trigger's Avatar
    Join Date
    Jun 2003
    Location
    Eagan
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm using a foreach loop becuase there is a list of email addresses with the potential for multiple selections, if you want to email the $message to more than one person. emailTo is a list of internal employees, while customerEmail is a list of customer contacts. Register globals is turned on. Any other suggestions? What about a while loop? I've used them before. Here's an example of the array being built in the form. I'll do emailTo
    PHP Code:
     <select name="emailTo[]" size="7" multiple="multiple" id="emailTo">
                    <?php
    do {  
    ?>
                    <option value="<?php echo $row_technSales['emailAddress']?>"><?php echo $row_technSales['realName']?></option>
                    <?php
    } while ($row_technSales mysql_fetch_assoc($technSales));
      
    $rows mysql_num_rows($technSales);
      if(
    $rows 0) {
          
    mysql_data_seek($technSales0);
          
    $row_technSales mysql_fetch_assoc($technSales);
      }
    ?>
                  </select>


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
  •