Time out and memory limits (ver4b3)
Posted: Thu Jan 29, 2009 8:32 pm
I am using the following code send fairly lengthy emails to up to about 1,000 recipients at a time. The process works for one or two recipients, but fails (fatal error) when it gets above about 100. At first the errors were time out variety, so I increased the max_time in php.ini. Then they were memory_limit, which I have set at 32M, and which according to what I have read, should be plenty. I must be doing something wrong.
In short, this application takes inputed html carried as a session and puts a header and footer and sends it to a list from a database (I have replaced personal information with sample text).
I am using the 4.0 beta3
In short, this application takes inputed html carried as a session and puts a header and footer and sends it to a list from a database (I have replaced personal information with sample text).
I am using the 4.0 beta3
Code: Select all
<?php
session_name ('sendemail');
session_start();
include ('./includes/header.html');
require ('./includes/mysql_connect.php'); //connects to the database
$additions = $_POST['additions'];
$subject = $_SESSION['subject'];
$count = 0;
//Include this needed file
require_once '/path/to/swift/swift_required.php';
// commented out because I couldn't get it to work--> require_once "/path/to/swift/classes/Swift/Plugins/AntiFloodPlugin.php";
//Start the mailer
$mailer = new Swift_Mailer(Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -t -i'));
// commented out because I couldn't get it to work--> $mailer->attachPlugin(new Swift_Plugin_AntiFlood(200, 10), "anti-flood");
$message = Swift_Message::newInstance();
foreach ($additions as $value) {
$query = "SELECT email, first_name, last_name FROM fulldata WHERE briusaid='$value'";
$result = mysql_query($query) or die (mysql_error());
$email = mysql_result($result,0,"email");
$fname = mysql_result($result,0,"first_name");
$lname = mysql_result($result,0,"last_name");
$html='<html>
<table width="600" border="0">
<tr><td>
<table width="100%" border="0">
<tr>
<td>
<font face="Verdana, Arial, Helvetica, sans-serif" color="#666666" size="2"><img src="http://www.example.com/image.gif" width="150" height="47" alt="" border="0" align=""></font>
</td>
<td> </td>
</tr>
</table>
<p><font color="#666666" face="Verdana, Arial, Helvetica, sans-serif" size="2">Dear' .$fname. ',</p>';
$html.=$_SESSION['html'];
$html.='
<p>Sample closing text...</p>
</td></tr></table>
</body></html>';
$no_html = strip_tags($html);
//Create a message
$message->setSubject($subject)
->addPart($no_html, 'text/plain')
->addPart($html, 'text/html')
->setFrom(array('me@example.com => 'My Name'))
->setTo(array($email => $fname. ' '. $lname));
//Send it
$mailer->send($message);
$count = $count +1;
}
echo "$count emails sent.";
mysql_close();
$_SESSION = array(); // Destroy the variables.
session_destroy(); // Destroy the session itself.
include ('./includes/footer.html');
?>