troubleshooting Question

phpmailer w/ mysql db

Avatar of rockmansattic
rockmansattic asked on
PHP
2 Comments1 Solution419 ViewsLast Modified:
I have a db with 126 email addrs.  phpmailer did work perfectly, but now, it will get about 1/2 way finished and the browser will lockup> then start to error.  I have error trapping to see which emails didnt get sent to, and it is about half.

When I run a test email, the browser locks up, and then when I shut it down... it takes the server a couple of minutes to allow me back into the site?  

Any ideas?  I am unsure if the ISP has upgraded.

CODE>>

<?php require_once('../Connections/conn.php'); ?>
<?php
session_start();
$error=0;
require("/home/mallardp/public_html/class.phpmailer.php");

$ref= parse_url(getenv("HTTP_REFERER"));
if($ref['host']=="website.com" || $ref['host']=="www.website.com"){
$path=1;
}else {$path=0;}

if($ref['path']=="/members/forum_reply.php"&& $path == 1){
//if(1==1){
$topicheader=$_POST['topicheader'];
$message=$_POST['message'];
$poster = $_POST['poster'];
$topic_text = $_POST['topic_text'];



$mail = new PHPMailer();
$mail->From     = "DoNotReply@website.com";
$mail->FromName = "websiteForum";
$mail->Mailer   = "smtp";
$mail->Subject = "Topic: ".$topicheader;


mysql_select_db($database_website, $website);

$query  = "SELECT * FROM users where getforum_email = 1 order by user_id";
$result = @MYSQL_QUERY($query);

while ($row = mysql_fetch_array ($result))
{
    // HTML body
    $body = "Hello " . $row["fname"] . ", <br><br>";
    $body .= "$poster has submitted a reply to the Forum.  <br><br>Topic:<b>".$topicheader."</b><br>";
      $body .= $topic_text."<br><br>Their Reply:<br>";
      $body .= $message;
      $body .= "<br><br>If you would like to reply to this message, Login to the <a href=\"http://www.website.com/login.php\" target=\"blank\">websiteMembers</a> section.<br><br>If you no longer wish to receive emails generated from the websiteForum, Login to your account, Click on Forum, then Click on Email Status.<br>";
      $body .= "This will update your account to <i>Passive</i>. You will still be able to view the forums by logging on to the website.com Website.";
    $body .= "<br><br>Sincerely, <br>";
    $body .= "website";

    // Plain text body (for mail clients that cannot read HTML)
    $text_body  = "Hello " . $row["fname"] . ", \n\n";
      $text_body .= "$poster has submitted a reply to the  Forum.  \n\n Topic:".$topicheader." \n";
      $text_body .= $topic_text."\n\nTheir Reply:\n";
    $text_body .= $message;
      $text_body .= "\n\n\n If you would like to reply to this message, Login to the <a href=\"http://www.website.com/login.php\" target=\"blank\">website Members</a> section.\n\nIf you no longer wish to receive emails generated from the Forum, Login to your account, Click on Forum, then Click on Email Status.\n";
      $yext_body .= "This will update your account to Passive. You will still be able to view the forums by logging on to the Website.";

    $text_body .= "\n\n Sincerely, \n";
    $text_body .= "me";

    $mail->Body    = $body;
    $mail->AltBody = $text_body;
    $mail->AddAddress($row["emailaddress"], $row["fname"]);
    //$mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");
      
      
//$mail->Send();
    if(!$mail->Send()){
        $error++;
            //creates and logs errors
            $myFile = "nosendreply.txt";
            $fh = fopen($myFile, 'a') or die("can't open file");
            $stringData = $row["emailaddress"]." | ";
            fwrite($fh, $stringData);
            fclose($fh);
}
//else{$emailssent++;echo $emailssent."to".$row['emailaddress'].",";}


    // Clear all addresses and attachments for next loop
    $mail->ClearAddresses();
    $mail->ClearAttachments();
}
}

else{ echo"Something went wrong";//print_r($ref);
}
header(sprintf("Location: %s", $GoTo."?errors=$error"));

?>

ASKER CERTIFIED SOLUTION
Tomeeboy

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros