i’ve been bcc’ing myself on all eForm contacts to keep a record of them, but ideally i want to have a mysql copy of each email. i know eForm2db exists, but that seems to be more about creating a table with columns for each field in the form. i just want a backup of the email. so i wrote the following addition to eForm, which creates a table with fields `timestamp`, `to`, `from`, `fromname`, `replyto`, `cc`, `bcc`, `subject`, and `body`. $body is the result of the &report chunk being processed by eForm, so it should contain all the data from your form.
(in ’eform.inc.php’ around line #455 in v1.4.4.6):
##################################
## CUSTOM - RECORD MAIL IN DATABSE
##################################
$backupTableFull = $modx->getFullTableName('eform_backup');
$backupTable = explode('.', $backupTableFull);
##################################################
## CHECK IF CUSTOM TABLE EXISTS. IF NOT, CREATE IT
##################################################
$tableNames = $modx->db->query("SHOW TABLES");
while($eachTable = $modx->db->getRow($tableNames, 'num')){
$allTables[] = $eachTable[0];
}
if(!in_array($backupTable, $allTables)){
$createTable = $modx->db->query("CREATE TABLE IF NOT EXISTS ".$backupTableFull." (`id` int(11) unsigned NOT NULL auto_increment,`timestamp` datetime NOT NULL,`to` text NOT NULL,`from` text NOT NULL,`fromname` text NOT NULL,`replyto` text NOT NULL,`cc` text NOT NULL,`bcc` text NOT NULL,`subject` text NOT NULL,`body` text NOT NULL,PRIMARY KEY (`id`))");
if(!$createTable){
return $this->FormatMessage($modx->db->getLastError);
}
}
##################
## INSERT THE DATA
##################
$backupSQL = "INSERT INTO ".$backupTableFull." (`timestamp`,`to`,`from`,`fromname`,`replyto`,`cc`,`bcc`,`subject`,`body`) VALUES (NOW(),'".$modx->db->escape($to)."','".$modx->db->escape($from)."','".$modx->db->escape($fromname)."','".$modx->db->escape($replyto)."','".$modx->db->escape($cc)."','".$modx->db->escape($bcc)."','".$modx->db->escape($subject)."','".$modx->db->escape($report)."')";
$modx->db->query($backupSQL);
####################################
## / CUSTOM - RECORD MAIL IN DATABSE
####################################
i just copied the ’eForm’ snippet, and all the code, and renamed it to ’eFormDB’, so in my resources i just call ’[!eFormDB? ... !]’ instead of ’[!eForm? ... !]’.