#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2007
    Posts
    52
    Rep Power
    7

    Post Progress bar with phpmailer


    Please how can l add this progress bar to my phpmailer code.

    <!-- Progress bar holder -->
    <div id="progress" style="width:500px;border:1px solid #ccc;"></div>
    <!-- Progress information -->
    <div id="information" style="width"></div>


    PHP Code:
    // Progress bar script
    // Total processes
    $total 10;
     
    // Loop through process
    for($i=1$i<=$total$i++){
        
    // Calculate the percentation
        
    $percent intval($i/$total 100)."%";
     
        
    // Javascript for updating the progress bar and information
        
    echo '<script language="javascript">
        document.getElementById("progress").innerHTML="<div style=\"width:'
    .$percent.';background-color:#ddd;\">&nbsp;</div>";
        document.getElementById("information").innerHTML="'
    .$i.' row(s) processed.";
        </script>'
    ;
     
        
    // This is for the buffer achieve the minimum size in order to flush data
        
    echo str_repeat(' ',1024*64);
     
        
    // Send output to browser immediately
        
    flush();
     
        
    // Sleep one second so we can see the delay
        
    sleep(1);

    PHP Code:
    if(isset($_POST['action'])== "Coform"){ 
    $action=$_POST['action']; 
    $message=$_POST['message']; 
    $emaillist=$_POST['emaillist']; 
    $from=$_POST['from']; 
    $replyto=$_POST['replyto']; 
    $subject=$_POST['subject']; 
    $realname=$_POST['realname']; 
    $file_name=$_POST['file']; 

            
    $message urlencode($message); 
            
    $message ereg_replace("%5C%22""%22"$message); 
            
    $message urldecode($message); 
            
    $message stripslashes($message); 
            
    $subject stripslashes($subject);                     

            if (!
    $from && !$subject && !$message && !$emaillist){ 
            print 
    "Please complete all fields before sending your  
    message."

            exit;     
        } 
    $allemails split("\n"$emaillist); 
     
    $numemails count($allemails); 
            
              for(
    $x=0$x<$numemails$x++){ 
                    
    $to $allemails[$x]; 
                    if (
    $to){ 
                    
    $to ereg_replace(" """$to); 
                    
    $message ereg_replace("&email&"$to$message); 
                    
    $subject ereg_replace("&email&"$to$subject); 
                    print 
    $to......."
                    
    flush(); 
                                    
                    
    $mail = new PHPMailer();
                    
    $mail->IsHTML(true);
                    
    $mail->CharSet "text/html; charset=UTF-8;";
                    
    $mail->IsSMTP();
                    
    $mail->WordWrap 80;
                    
    $mail->SMTPAuth true// enable SMTP authentication
                    
    $mail->SMTPSecure "ssl"// sets the prefix to the servier
                    
    $mail->Host "smtp.gmail.com"// sets GMAIL as the SMTP server
                    
    $mail->SMTPDebug  1
                    
    $mail->Port 465// set the SMTP port for the GMAIL server
                    
    $mail->Username "username"// GMAIL username
                    
    $mail->Password "password"// GMAIL password
                    
    $mail->AddReplyTo($replyto$realname);
                    
    $mail->SetFrom($from$replyto);                
                    
    $mail->FromName $realname;  // set from Name                
                    
    $mail->Subject $subject;

                    
    //////$mail->AddAttachment("test.doc");
                    
    $mail->Body $message;
                    
    $mail->AltBody  =  $message;
                    
    $mail->AddAddress("$to"); // to Address
                    
                    
    $mail->AddAttachment("files/$attach");

                    
    //$mail->AddCC("member@mail.com", "Mr.Member"); //CC
                    //$mail->AddBCC("member@mail.com", "Mr.Member"); //CC

                    
    $mail->set('X-Priority''1'); //Priority 1 = High, 3 = Normal, 5 = low

                    
    $mail->Send();
                    print 
    "sent<br>"
                     
    $mail->ClearAddresses();
                    
                    
    flush(); 
                    } 
                    } 
                    
                    

    ?> 

    My own integration keeps duplicating or repeating sending mails instead of one per email address and also progress bar is counting before even sending the mail.

    PHP Code:

    <?php      
                        
                        
    if(isset($_POST['action'])== "Coform"){ 
    $action=$_POST['action']; 
    $message=$_POST['message']; 
    $emaillist=$_POST['emaillist']; 
    $from=$_POST['from']; 
    $replyto=$_POST['replyto']; 
    $subject=$_POST['subject']; 
    $realname=$_POST['realname']; 
    $file_name=$_POST['file']; 

            
    $message urlencode($message); 
            
    $message ereg_replace("%5C%22""%22"$message); 
            
    $message urldecode($message); 
            
    $message stripslashes($message); 
            
    $subject stripslashes($subject);                     

            if (!
    $from && !$subject && !$message && !$emaillist){ 
            print 
    "Please complete all fields before sending your  
    message."

            exit;     
        } 
    $allemails split("\n"$emaillist); 
     
    $numemails count($allemails); 
            
              for(
    $x=0$x<$numemails$x++){ 
                    
    $to $allemails[$x]; 
                    if (
    $to){ 
                    
    $to ereg_replace(" """$to); 
                    
    $message ereg_replace("&email&"$to$message); 
                    
    $subject ereg_replace("&email&"$to$subject); 
                    
    $total $numemails;
     
    // Loop through process
    for($i=1$i<=$total$i++){
        
    // Calculate the percentation
        
    $percent intval($i/$total 100)."%";
     
        
    // Javascript for updating the progress bar and information
        
    echo '<script language="javascript">
        document.getElementById("progress").innerHTML="<div style=\"width:'
    .$percent.';background-color:#ddd;\">&nbsp;</div>";
        document.getElementById("information").innerHTML="'
    .$i.' row(s) processed.";
        </script>'
    ;
     
        
    // This is for the buffer achieve the minimum size in order to flush data
        
    echo str_repeat(' ',1024*64);
     
        
    // Send output to browser immediately
        
    flush();
     
        
    // Sleep one second so we can see the delay
        
    sleep(1);
    }                
    // Tell user that the process is completed
    echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>';
                    
                    
                    print 
    $to......."
                    
    flush(); 
                                    
                    
    $mail = new PHPMailer();
                    
    $mail->IsHTML(true);
                    
    $mail->CharSet "text/html; charset=UTF-8;";
                    
    $mail->IsSMTP();
                    
    $mail->WordWrap 80;
                    
    $mail->SMTPAuth true// enable SMTP authentication
                    
    $mail->SMTPSecure "ssl"// sets the prefix to the servier
                    
    $mail->Host "smtp.gmail.com"// sets GMAIL as the SMTP server
                    
    $mail->SMTPDebug  1
                    
    $mail->Port 465// set the SMTP port for the GMAIL server
                    
    $mail->Username "username"// GMAIL username
                    
    $mail->Password "password"// GMAIL password
                    
    $mail->AddReplyTo($replyto$realname);
                    
    $mail->SetFrom($from$replyto);                
                    
    $mail->FromName $realname;  // set from Name                
                    
    $mail->Subject $subject;

                    
    //////$mail->AddAttachment("test.doc");
                    
    $mail->Body $message;
                    
    $mail->AltBody  =  $message;
                    
    $mail->AddAddress("$to"); // to Address
                    
                    
    $mail->AddAttachment("files/$attach");

                    
    //$mail->AddCC("member@mail.com", "Mr.Member"); //CC
                    //$mail->AddBCC("member@mail.com", "Mr.Member"); //CC

                    
    $mail->set('X-Priority''1'); //Priority 1 = High, 3 = Normal, 5 = low

                    
    $mail->Send();
                    print 
    "spammed<br>"
                     
    $mail->ClearAddresses();
                    
                    
    flush(); 
                    } 
                    } 
                    
                    

    ?>

    What l want to achieve is to show a progress bar when sending each mail using phpmailer.

    please any help will be appreciated. thanks
    Last edited by wasamtech; December 4th, 2012 at 12:23 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,466
    Rep Power
    594
    You can't with qualifications. PHP is server side and stateless. The server does not communicate with the client unless the client requests something first and then the server does not know what happened previously. However, you can achieve something similar using Ajax but I doubt it would be very reliable due to network latency and other factors. In any case if PHPMailer is running so slow you think you need a progress bar I would suggest you investigate why as that should not be the case.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. For POny!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    Amsterdam
    Posts
    416
    Rep Power
    115
    In addition to GW1500se I have seen a method to accomplish this.
    indeed with ajax. What happens is that in the loop that send the emails the succesfully send emails are stored in a database. like:

    Code:
    id email time result
    Than an ajax script queries the database with a certain interval and gives the end-user some feedback.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2007
    Posts
    52
    Rep Power
    7
    Thanks for the suggestion, please can you help write the database function or code to achieve this. Any help will be highly appreciated.

    Thanks all
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,466
    Rep Power
    594
    I doubt you will find anyone willing to write code for you for free on this form (although it does happen on rare occasions) as this is a help forum not the hire a programmer forum. I suggest you research it yourself and try some things. Then when you get stuck, post what you did here and explain where it seems to be going wrong.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo