To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Coding

Coding Help with PHP coding

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 05-11-2006, 04:40 PM   #1
peppino
Member
 
Join Date: Feb 2004
Posts: 74
Unhappy phpmailer please help!

i am using the code below to send emails out to a mailing list. its takes 2 emails(right now, probably 50 when im done) from the database and sends out and email. then it submits a hidden form to the same page after it sends two emails. it then grabs the next 2 and sends those out. it does this till all emails are sent out. so basically it sends 2 emails, submits hidden form back to the same page, then send 2 more emails out. it does this till all emails are sent.

my problem is that while the script is executing none of the html is output and visible in the browser until the $mailer>send() is done. and when it appears it only appears for 1 sec then disappears.

i have tried all kinds of things like output buffering, sleep(), and stuff like that but it still does not work. can ANYONE PLEASE help me figure this out? ive been at it for a few days now.

HERE IS THE CODE
------------------------------------------
PHP Code:
<?php
include "header.php";
$dbhost = 'localhost';
$dbusername = 'user';
$dbpasswd = 'pw';
$database_name = 'mydb';
    
if (!
$action) {
    echo
"<b>Send Newsletter</b><br><br>\n";

echo
"<span class=\"headers\">Send message to Mailinglist</span><br>\n";
echo
"<form id=\"form1\" name=\"form1\" method=\"post\" action=\"mailtester.php?action=send_newsletter\">
<table width=\"90%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\">
  <tr>
    <td width=\"100\" align=\"right\" valign=\"top\">Subject:</td>
    <td width=\"450\" align=\"left\" valign=\"top\"><input type=\"text\" name=\"subject\" /></td>
  </tr>
  <tr>
    <td width=\"100\" align=\"right\" valign=\"top\">Message:</td>
    <td width=\"450\" align=\"left\" valign=\"top\"><textarea name=\"body\" style=\"width: 100%; height: 450px;\" wrap=\"VIRTUAL\" id=\"txt\"></textarea></td>
  </tr>
  <tr>
    <td width=\"100\" align=\"right\" valign=\"top\">&nbsp;</td>
    <td width=\"450\" align=\"right\" valign=\"top\">
      <input type=\"submit\" name=\"Submit\" value=\"Submit\" /></td>
  </tr>
</table>
</form>"
;

}else{





if (
$action == "send_newsletter") {
    
$counter=$_POST['counter'];
    
$count=0;
    
$count2=0;
    require (
"class.phpmailer.php");
    
$mail = new phpmailer;
    
$subject=stripslashes(urldecode($subject));
    
$body=stripslashes(urldecode($body));
    
$mail->From     = "me@me.com";
    
$mail->FromName = "me";
#    $mail->WordWrap = 75;
    
$mail->UseMSMailHeaders = true;
    
$mail->AddCustomHeader("X-Mailer: mailer - Email Interface");
    
$mail->Subject = $subject;
    
$mail->Body    = $body;
    
$mail->IsHTML(true);
    echo
"<b>Send Newsletter</b><br><br>\n";
$connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd")
    or die (
"Couldn't connect to server.");
    
$db = mysql_select_db("$database_name", $connection)
    or die(
"Couldn't select database.");

    
$count=0;

    echo
" <table align=\"center\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\" width=\"100%\">\n";

    if (!
$counter){
    
$counter=0;
    }

    
$count+=$counter;
  
//GET USER EMAILS IN CHUNKS OF 25, STARTING AT TALLY #//
    
$query = "SELECT * FROM mailinglist LIMIT $count,2";
    
$result = mysql_query($query) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());
//GET TOTAL NUMBER OF EMAILS NEEDED TO BE SEND

    
while ($db = mysql_fetch_array($result)) {
        if (!
get_cfg_var('safe_mode')) {set_time_limit(0);}
        
$mail->AddAddress("$db[email]", "");
        if(!
$mail->Send()) {
        echo
"   <tr>\n";
            echo
"    <td class=\"class3\">\n";
        echo
"<b> There was an error sending the message to $to !!!</b>";
            echo
"    </td>\n";
        echo
"  </tr>\n";
        } else {
        echo
"   <tr>\n";
            echo
"    <td class=\"class3\">\n";
        echo
"     <small>Mail to ".$db['email']." with subject: $subject -> <b>sent</b> !</small>";
            echo
"    </td>\n";
        echo
"  </tr>\n";
        }

        
$mail->ClearAllRecipients();
        
$count++;
        
$count2++;
    }


    echo
"</table>\n";
    echo
"<br>$count Newsletters sent.<br>\n";


   
mysql_close;

    if (
$count2==2) {
    
$redirect="newsletter";
    echo
"<small>... sending in progress - please be patient ...</small>";
    } else {
    echo
"DONE";
    }
    
   if (
$redirect=="newsletter") {

    echo
"

            <form method=
\"POST\" name=\"form\" id=\"form\" action=\"mailtester.php\">

            <input type=hidden name=
\"action\" value=\"send_newsletter\">

            <input type=hidden name=
\"counter\" value=\"$count\">

           <input type=hidden name=
\"subject\" value=\"".urlencode($subject)."\">

            <input type=hidden name=\"body\" value=\""
.urlencode($body)."\">

        </form>

        <script language=javascript>document.form.submit();</script>"
;

}
}
//end if send newsletter



}
include
"footer.php";
?>
peppino is offline   Reply With Quote
Old 05-11-2006, 08:32 PM   #2
peppino
Member
 
Join Date: Feb 2004
Posts: 74
anyone?
peppino is offline   Reply With Quote
Old 05-12-2006, 01:41 PM   #3
peppino
Member
 
Join Date: Feb 2004
Posts: 74
i tried some more output buffering but that did not help, maybe i was not doing it right?
peppino is offline   Reply With Quote
Old 05-15-2006, 08:49 PM   #4
peppino
Member
 
Join Date: Feb 2004
Posts: 74
still no one?
peppino is offline   Reply With Quote
Old 05-17-2006, 03:54 PM   #5
essexboyracer
Member
 
Join Date: Jun 2001
Location: UK
Posts: 51
fresh thought, do a clean install, re-do your script but with the minimum, try and iron out the bumps by adding individually adding the things you want in. I have used phpMailer successfully in mo own mess and it seems to work fine.
essexboyracer is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 07:37 AM.








Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.