Forum Moderators: coopster

Message Too Old, No Replies

attachments using phpmailer

         

kkonline

8:22 am on Jun 9, 2008 (gmt 0)

10+ Year Member



hi all,
I am using the phpmailer to send an attachment(3MB) to to all the members in the database, however in doing so, i receive the following error Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 4680430 bytes) in /home/mysite/public_html/dir1/phpmailer/class.smtp.php on line 308

$mail->FromName = "mysite.org";
$mail->From = "noreply@mysite.org";
$mail->AddReplyTo("noreply@mysite.org", "mysite");

$mail->Subject = $subject;
$mail->Body = $message;
$mail->WordWrap = 65;

$sql = "SELECT * FROM invites_test WHERE `invitation` = 0 LIMIT 0, 3";
$result = mysql_query($sql) or die(mysql_error());

//attachment
$mail->AddAttachment("/home/mysite/public_html/dir1/dir/attach.zip", "attach.zip");
//attachment

while($row = mysql_fetch_array($result)){
$email=$row['email'];
$mail->AddAddress($row['email']);

$mail->Send();
mysql_query("UPDATE invites_test SET invitation = 1 WHERE email LIKE '".$email."%'");
$mail->ClearAddresses();
}
echo 'Invitation has been sent.';
?>

The purpose is to send attachment to all th members

eelixduppy

2:25 pm on Jun 10, 2008 (gmt 0)



You must either 1) Set your max memory limit higher in php.ini so that you can use more memory for this script, and/or 2) Split this process up into smaller parts and run a cron to send them all out over time. How many emails are being sent out? I'd imagine a decent amount. Also with a script like this, make sure to optimize it as much as possible, and also free resources when they aren't needed anymore.

kkonline

8:25 am on Jul 13, 2008 (gmt 0)

10+ Year Member



is it possible to change the php.ini configuration on a shared host? If yes how to do it?

vincevincevince

8:50 am on Jul 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't think the problem is with memory allocation; more something which is not being cleared. Try putting the whole class into the loop and setting the data each time - and then destroying the object before repetition.

webfoo

5:50 pm on Jul 13, 2008 (gmt 0)

10+ Year Member



Here's a practical solution: Post the file on your website and send all the members a link.