The following code illustrates my problem. I'm sending a node with file attachments as an email message. The first recipient (first call to mimemail) will receive the attachment but it will not be sent to the rest. A quick look in mimemail.inc reveals some use of static variables for attachments. I guess it may be the reason for this.
Code:
//This is my send function
function send_node($node, $recipient) {
$message = new stdClass();
$message->sender = 'ourmail@ourdomain.no' ;
$message->recipient = trim($recipient);
$message->subject = $node->title;
$message->body = $node->body;
$message->plaintext = FALSE;
$message->headers = array();
$message->text = strip_tags($node->body);
$message->attachments = array();
foreach($node->files as $id => $file) {
$message->attachments[] = array('filepath' => $file->filepath, 'filemime' => $file>filemime);
}
return mimemail(
$message->sender,
$message->recipient,
$message->subject,
$message->body,
$message->plaintext,
$message->headers,
$message->text,
$message->attachments
);
}
// I use it like this
$q = "SELECT email FROM mydata";
$result = db_query($q);
while ($obj = db_fetch_object($result)) {
$node = node_load(5386);
$sr = send_node($node, $obj->email);
}
Comments
Comment #1
sgabe commentedMarking as a duplicate of #358439: Images are only in the first message.
Comment #2
danielbeeke2 commentedhttps://drupal.org/node/358439#comment-1426276
this one fixes it