Mail re-send from Outgoing mail
3 posts by 2 authors in: Forums > CMS Builder
Last Post: September 30, 2015 (RSS)
Hi,
Is there any way to add a resend option to the "Outgoing mail" folder sent items?
(I' am working with my host to avoid errors due mail sending (timeouts, SSL errors,...) but in some cases mails are not successfully send.)
Thank you in advance,
Karls
Hey Karls,
Unfortunately there isn't a way you can re-send mail in the outgoing mail log by default. You'd have to write a script that goes through the log and re-sends messages as required. Something like this should work:
<?php
// load viewer library
$libraryPath = 'cmsb/lib/viewer_functions.php';
$dirsToCheck = array('C:/wamp/www/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
$mailLog = mysql_select('_outgoing_mail', "TRUE ORDER BY `createdDate` DESC LIMIT 0, 10 ");
foreach ($mailLog as $logItem) {
echo "<p>Resending '{$logItem['subject']}'</p>\r\n";
$errors = sendMessage(array(
'from' => $logItem['from'],
'to' => $logItem['to'],
'subject' => $logItem['subject'],
'text' => $logItem['text'],
'html' => $logItem['html'],
'headers' => array(
"CC" => $logItem['cc'],
"BCC" => $logItem['bcc'],
"Reply-To" => $logItem['reply-to'],
),
));
if($errors){
echo "<p>ERRORS! $errors</p>\r\n";
}
}
This is just example code, you'll need to modify it to work with your requirements. Make sure you do a full backup of your DB before running it, and test with email sending in log only.
So the code above will get the 10 newest sent emails and will resend them.
This script will also add another log record for each email that gets sent .
Cheers,
Greg
PHP Programmer - interactivetools.com
Hi Greg,
This is a great start, i probably make a plugin to do this from the system folder actions.
Thank you,
Karls