downah Posted July 5, 2012 Share Posted July 5, 2012 Hi guys, Wondering if you could guys help me a little bit as I am messing around with PHP mailer, I have this code modified but from here http://www.askapache.com/php/phpfreaks-eric-rosebrocks-phpmailer-tutorial.html Sending single emails is working fine through PHP mailer, but trying to send to multiple emails from a database is currently not working.. although I am wondering if it is actually doing anything with the emails from the database, I don't want to use $mailer->AddAddress(''); as everyone in the mailing list will see each others email.. The script does succeed and print the names, (edit) but does not send any emails out! At least none get received..(not in spam either) any help? Sorry if this is very obvious! <?php // Grab our config settings require_once($_SERVER['DOCUMENT_ROOT'].'/mail/config.php'); // Grab the FreakMailer class require_once($_SERVER['DOCUMENT_ROOT'].'/mail/lib/MailClass.inc'); //set execution time limit to 5 minutes $safeMode = ( @ini_get("safe_mode") == 'On' || @ini_get("safe_mode") === 1 ) ? TRUE : FALSE; if ( $safeMode === FALSE ) { set_time_limit(300); // Sets maximum execution time to 5 minutes (300 seconds) // ini_set("max_execution_time", "300"); // this does the same as "set_time_limit(300)" } echo "max_execution_time " . ini_get('max_execution_time') . "<br>"; //db connection $con = mysql_connect("xx","xx","xx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xx", $con); // Setup body $textBody = "Dear {MEMBER_NAME},\n\nTEST"; $htmlBody = "Dear {MEMBER_NAME},<br /><br />TEST"; // instantiate the class $mailer = new FreakMailer(); // Get the user's Email $sql = mysql_query("SELECT displayname,email FROM engine4_users2")or die(mysql_error()); //lets reset the time limit of the server everytime an email is sent to bypass maximum while (1==1) { set_time_limit(30); // sets (or resets) maximum execution time to 30 seconds) // .... put code to process in here while($row = mysql_fetch_object($sql)) { // Send the emails in this loop. $member_name = $row->displayname; if($row->MailType == 'html') { $mailer->Body = str_replace('{MEMBER_NAME}', $member_name, $htmlBody); $mailer->IsHTML(true); $mailer->AltBody = str_replace('{MEMBER_NAME}', $member_name, $textBody); } else { $mailer->Body = str_replace('{MEMBER_NAME}', $member_name, $textBody); $mailer->isHTML(false); } $mailer->Send(); $mailer->ClearAddresses(); $mailer->ClearAttachments(); $mailer->IsHTML(false); echo "Mail sent to: " . $member_name . "<br />"; } usleep(1000000); // sleep for 1 million micro seconds - will not work with Windows servers / PHP4 // sleep(1); // sleep for 1 seconds (use with Windows servers / PHP4 if (1!=1) { break; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/265284-php-mailer/ Share on other sites More sharing options...
trq Posted July 6, 2012 Share Posted July 6, 2012 I assume you have an email server installed and configured? Quote Link to comment https://forums.phpfreaks.com/topic/265284-php-mailer/#findComment-1359559 Share on other sites More sharing options...
Isset1988 Posted July 6, 2012 Share Posted July 6, 2012 Take a look here http://forums.phpfreaks.com/index.php?topic=362006.0 Quote Link to comment https://forums.phpfreaks.com/topic/265284-php-mailer/#findComment-1359568 Share on other sites More sharing options...
downah Posted July 6, 2012 Author Share Posted July 6, 2012 Haha but I linked that thread to myself.. he is a bit further behind than I am it seems so looking at that thread doesnt really help.. Like I said I can send single emails but now trying this script for sending to all my emails in the database.. the emails are not being sent, although the script says the emails are successfully sent.. Quote Link to comment https://forums.phpfreaks.com/topic/265284-php-mailer/#findComment-1359645 Share on other sites More sharing options...
downah Posted July 6, 2012 Author Share Posted July 6, 2012 So I got further.. mails are sending out, although all the mails are being sent to the first person in the loop, but showing the right names.. <?php // Grab our config settings require_once($_SERVER['DOCUMENT_ROOT'].'/mail/config.php'); // Grab the FreakMailer class require_once($_SERVER['DOCUMENT_ROOT'].'/mail/lib/MailClass.inc'); //set execution time limit to 5 minutes $safeMode = ( @ini_get("safe_mode") == 'On' || @ini_get("safe_mode") === 1 ) ? TRUE : FALSE; if ( $safeMode === FALSE ) { set_time_limit(300); // Sets maximum execution time to 5 minutes (300 seconds) // ini_set("max_execution_time", "300"); // this does the same as "set_time_limit(300)" } echo "max_execution_time " . ini_get('max_execution_time') . "<br>"; //db connection $con = mysql_connect("xxt","xx","xx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xx", $con); // Setup body $textBody = "Dear {MEMBER_NAME},\n\nCheck out PHP Freaks: http://www.phpfreaks.com\n\nSincerely,\nAdmin"; $htmlBody = "Dear {MEMBER_NAME},<br /><br />Check out PHP Freaks: http://www.phpfreaks.com<br /><br />Sincerely,<br />Admin"; // instantiate the class $mailer = new FreakMailer(); // Get the user's Email $sql = mysql_query("SELECT displayname,email FROM engine4_users2")or die(mysql_error()); //lets reset the time limit of the server everytime an email is sent to bypass maximum while (1==1) { set_time_limit(30); // sets (or resets) maximum execution time to 30 seconds) // .... put code to process in here while($row = mysql_fetch_object($sql)) { // Send the emails in this loop. $member_name = $row->displayname; $mailer->AddBCC($row->email); $mailer->Body = str_replace('{MEMBER_NAME}', $member_name, $htmlBody); $mailer->IsHTML(true); $mailer->AltBody = str_replace('{MEMBER_NAME}', $member_name, $textBody); $mailer->Send(); $mailer->ClearAddresses(); $mailer->ClearAttachments(); $mailer->IsHTML(false); echo "Mail sent to: " . $member_name . "<br />"; } usleep(1000000); // sleep for 1 million micro seconds - will not work with Windows servers / PHP4 // sleep(1); // sleep for 1 seconds (use with Windows servers / PHP4 if (1!=1) { break; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/265284-php-mailer/#findComment-1359649 Share on other sites More sharing options...
downah Posted July 6, 2012 Author Share Posted July 6, 2012 Got it working, incase anyone else is wondering here is the working code: <?php // Grab our config settings require_once($_SERVER['DOCUMENT_ROOT'].'/mail/config.php'); // Grab the FreakMailer class require_once($_SERVER['DOCUMENT_ROOT'].'/mail/lib/MailClass.inc'); //set execution time limit to 5 minutes $safeMode = ( @ini_get("safe_mode") == 'On' || @ini_get("safe_mode") === 1 ) ? TRUE : FALSE; if ( $safeMode === FALSE ) { set_time_limit(300); // Sets maximum execution time to 5 minutes (300 seconds) // ini_set("max_execution_time", "300"); // this does the same as "set_time_limit(300)" } echo "max_execution_time " . ini_get('max_execution_time') . "<br>"; //db connection $con = mysql_connect("xx","xx","xx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xx", $con); // Setup body $textBody = "Dear {MEMBER_NAME},\n\nCheck out PHP Freaks: http://www.phpfreaks.com\n\nSincerely,\nAdmin"; $htmlBody = "Dear {MEMBER_NAME},<br /><br />Check out PHP Freaks: http://www.phpfreaks.com<br /><br />Sincerely,<br />Admin"; // instantiate the class $mailer = new FreakMailer(); // Get the user's Email $sql = mysql_query("SELECT displayname,email FROM engine4_users2")or die(mysql_error()); //lets reset the time limit of the server everytime an email is sent to bypass maximum while (1==1) { set_time_limit(30); // sets (or resets) maximum execution time to 30 seconds) // .... put code to process in here while($row = mysql_fetch_object($sql)) { // Send the emails in this loop. $member_name = $row->displayname; $mailer->AddAddress($row->email); $mailer->Body = str_replace('{MEMBER_NAME}', $member_name, $htmlBody); $mailer->IsHTML(true); $mailer->AltBody = str_replace('{MEMBER_NAME}', $member_name, $textBody); $mailer->Send(); $mailer->ClearAddresses(); $mailer->ClearAttachments(); $mailer->IsHTML(false); echo "Mail sent to: " . $member_name . "<br />"; } usleep(1000000); // sleep for 1 million micro seconds - will not work with Windows servers / PHP4 // sleep(1); // sleep for 1 seconds (use with Windows servers / PHP4 if (1!=1) { break; } } ?> I realized it is sending one email by one, so you can add an address without the others seeing one.. Quote Link to comment https://forums.phpfreaks.com/topic/265284-php-mailer/#findComment-1359651 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.