Weird Emails and Other Aspects

I love the fact this large program is free BUT there are some aspects that should be addresses to help everyone as it makes much sense to do so.

EMAILS:

  • Fix the html code being submitted to email addresses(It’s not parsing and submitting
  • Automatically pull account based on email addresses checked
  • Your campaigns seem to send html code to email addresses and when we use a variable like a $name, it sends “$name” to the sent email
  • Not everyone has a dedicated server to send 500 emails in one blast, you should create a function to allow users to send a certain amount of emails, per so amount of seconds. Like when our other application on our server, we can send 1 email per 5 seconds(Shared Server) so I would like to contribute to this by offering a piece of our code that made it happen(WITHOUT SPAMMING NOR BLOCKING US FROM OUR OWN SERVER using hostgator), if you like… But here’s the order of process.
  1. Gather the variables needs like name, addresses, whatever we pick to send for campaign
  2. Gather the information variables for customers.
  3. Set email headers
  4. While statement
  5. Iterate both customer and campaign tables to append information to email along with campaign message and any $contact variables.
  6. After the first record has been read, appended and sent, wait 5 seconds before you move to record too using a simple command of “usleep(1000000)” or “sleep(10)”.
    7 After it’s done, THEN swing back around to the completion.

We also use this same method to send multiple invoicing emails on a timer that check every 1 hour. Total automation and no worries of having to go through each invoice 1 by 1. if anyone would like the piece of code from us, feel free to ask. It’s super ugly THUS gave us what we needed with our CRM/POS application we made.

  1. Remove the restriction about which file to use because that simply causes an issue with adding a png or jpg image period. We add it even when it’s 100 by 100 and still throws an error. Just rid of that restriction or whatever hidden file size restriction and let us add a big 4000x4000 if we want.

  2. You allow us to post to the activity stream, allow the stream to stay clean by allowing us to post to a certain user so the notification bubble becomes useful.

Contribution: Here is out code that we did with our CRM/POS system that allowed us to not only fully automate email campaigns regardless of the name, but also allowed us to send invoices out to each client. Total automation and no more worries of sending one by one on emails and invoices… Please note, code is super ugly, out of place maybe but I be darn if it didn’t save us hours on billing/marketing… Thank you guys for making a wonderful free app. If you have questions, message me, i will answer and we can put this into place and this will dup every other paid CRM

if ($getsubmit == ‘Launch Campaign’ ) {
$maxlimit = $_POST[‘maxlimit’];
//echo $maxlimit; die;

$targetlist = $_POST[‘target’];

$actualcount=0;
$ecount=0;
$count=0;
$stopatmax=0;
$emailcount=0;
$emailreset=0;

ini_set(‘display_errors’,‘off’);

include(‘Mail.php’);

//Where we store out login email info and just include it instead of typining it in directly in the code
include ("/opt/eopt.php");

//BELOW IS FOR MULTI SENDING
$rowsquery = mysql_query(“SELECT * FROM CUSTOMERS WHERE EMAIL > ‘’ AND EMAIL NOT LIKE ‘cmupdate’ AND EMAIL NOT LIKE ‘cmnothanks’ AND CAMPSTATUS = ‘0’ AND CAMPAIGN > ‘’ AND TARGETLIST = ‘$targetlist’ ORDER BY EMAIL ASC”)or die (mysql_error());

//echo $emailcount."----------".$maxlimit; die;

while($rowcamp = mysql_fetch_array($rowsquery)) {

$result = 0;
$camptype = $rowcamp[‘CAMPAIGN’];
$targettype = $rowcamp[‘TARGETLIST’];
$contact = $rowcamp[‘CONTACT’];
$campstatus = $rowcamp[‘CAMPSTATUS’];
$emailaddress = $rowcamp[‘EMAIL’];
$maxlimit = $_POST[‘maxlimit’];

//echo $maxlimit; die;

$getcampaign = mysql_query("SELECT * FROM COREMARKET WHERE CNAME = ‘$camptype’ ") or die (mysql_error());

while($rowcm = mysql_fetch_array($getcampaign)) {

$bodymsg='';
$footer='';

$cname = $rowcm[‘CNAME’]; //echo “$cname”;
$csub = $rowcm[‘SUBJECT’];
$cmessage = stripslashes($rowcm[‘MESSAGE’]."$footor");
$imagefile = $rowcm[‘TARGETDIR’].$rowcm[‘IMAGENAME’];
$camp = $rowcm[‘CAMPAIGN’];
$imagenameonly = $rowcm[‘IMAGENAME’];

$contact = ucwords(strtolower($contact));
$contact = strtok($contact, ’ ');

}

$cmessage = str_replace(’$contact’,"$contact", $cmessage);
//echo $cmessage; die;

//$recipients = ‘W&G Consultants coremarket@wgconsultant.com’;
$recipients = ‘WG Consultants email@website.com’;

$csub = stripslashes($csub);

//$headers[‘MIME-Version’] = ‘1.0\r\n’;
$headers[‘Content-Type’] = “text/html; charset=UTF-8;”;

$headers[‘From’] = “$recipients”;
$headers[‘To’] = “$emailaddress”;
$headers[‘Subject’] = “$csub”;

//Where our footer info is
include ("…/store/thelogininfofile.php");

$bodymsg .= nl2br($cmessage, false);
$bodymsg .= “



”;

//echo “$from - $h1 - $po1 - $au1 - $usr1 - $ps1”; die;

//FOOTOR
$footer = “
$storename
$storecity, $storestate. $storezip”. "

Phone: $storephone
Web: www.website.com

For more information, please contact us as we will answer any additional questions you may have.


";
//echo $footer;
//echo $bodymsg.$footer; die;

$result = $mail->send($emailaddress, $headers, $bodymsg.$footer);

//echo $result; die;
$emailcount++;
$emailcountreset++;	
//$result = 1;

if ($result == 1) {
mysql_query("UPDATE CUSTOMERS SET TARGETLIST = 'Follow Up', CAMPAIGN = 'Follow Up' WHERE EMAIL = '$emailaddress'");
mysql_query("UPDATE CUSTOMERS SET CAMPSTATUS = '1' WHERE EMAIL = '$emailaddress'");



	if ($maxlimit == '1') {

			//Resetting the increment assures an accurate count while iterating before the insert. Ex: 1.2.3.4.5...
			mysql_query("ALTER TABLE COREMARKETCOMPLETE AUTO_INCREMENT = 1");
			$dateit = date('Y-m-d H:i:s');
			$dateit2 = date('m-d-Y g:i A');
			$campuser = $_SESSION['us1'];

			mysql_query("INSERT INTO COREMARKETCOMPLETE VALUES ('','$camptype','$targettype','$dateit','$emailcount', '$campuser')");
	
		echo '<script>alert("CAMPAIGN (', $camptype ,')\n\nHAS BEEN SUCCESSFULLY SENT TO -', $emailcount ,'- EMAIL(S)!\n\n\nTarget List: ', $targettype, '\nDate: ',$dateit2,'\n\nTarget list have been converted to follow up campaign.  If you have not created a -Follow up- campaign, please do so now so that your next run will be for follow up automatically. ");</script>';

		echo "<b>LAST EMAIL SENT:</b><br /><hr />$bodymsg.$footer<br />Sent: $emailcount<br />Last Email:<b>$emailaddress<br />Max Limit: $maxlimit</b>";
		die;
		
		
	}
	

	//Send per count of emails before you sleep
	if ($emailcountreset == '5') {
		
		//Don't jack the server and get spam blocked
		sleep(10);
		//echo "<br />Slept for 6 seconds at $emailcount";
		
		//Let's reset the reset count so we can keep counting 6 at a time per 10 seconds for the next pause
		$emailcountreset=0;
		
		
	}
	
	//Send 1 per xx per hosting policy
	sleep(10);
	
	if ($emailcount == $maxlimit) {
		
	//Count the very last email sent so we are not down by 1 and send it
			//$emailcount++;
			$result = $mail->send($recipients, $headers, "CAMPAIGN SENT!<BR /><BR />Campaign: $camptype<br />Target List: $targettype<br />Total Emails: $emailcount<br /><br /><hr /><b>LAST EMAIL SENT:</b><br />$bodymsg<br /><br />$footer");
			
		//echo "Tried to send mail<br />";
		//$ip=$_SERVER['REMOTE_ADDR'];
		if($result == '1') {
			
			//Resetting the increment assures an accurate count while iterating before the insert. Ex: 1.2.3.4.5...
			mysql_query("ALTER TABLE COREMARKETCOMPLETE AUTO_INCREMENT = 1");
			$dateit = date('Y-m-d H:i:s');
			$dateit2 = date('m-d-Y g:i A');
			$campuser = $_SESSION['us1'];
			
			mysql_query("INSERT INTO COREMARKETCOMPLETE VALUES ('','$camptype','$targettype','$dateit','$emailcount', '$campuser')");
			echo '<script>alert("CAMPAIGN (', $camptype ,')\n\nHAS BEEN SUCCESSFULLY SENT TO -', $emailcount ,'- EMAIL(S)!\n\n\nTarget List: ', $targettype, '\nDate: ',$dateit2,'\n\nTarget list have been converted to follow up campaign.  If you have not created a -Follow up- campaign, please do so now so that your next run will be for follow up automatically. ");</script>';


			echo "<b>LAST EMAIL SENT:</b><br /><hr />$bodymsg.$footer<br />Sent: $emailcount<br />Last Email:<b>$emailaddress<br />Max Limit: $maxlimit</b>";
			die;
			
		}
		



		
	} 

	$bodymsg='';
	$footer='';

}

//IF ending for $_POST[‘submit’]
}

echo “$bodymsg.$footer
Sent: $emailcount”;
$bodymsg=’’;

}

}

1 Like

I’m not a developer, but if this code really does automate the sending of invoices to clients, I would love to see it integrated into a new SuiteCRM release sooner rather than later!

Yes it does, I’ve actually gone back to our own CRm/POS as suiteCRm is stripped down to the limits were it feels like a project rather than an actual line of software. It’s missinga lot that we need for our company but yes, that code allows you to automate sending of invoices to emails automatically. Our server has changed a bit but we are working on updates. But useable

Hi,

  • You can choose the batch size by going Admin > Campaign Email Settings. Here you can decrease it from 500

  • You can submit your code suggestion as pull request at: https://github.com/salesagility/SuiteCRM/pulls
    If people validate this code as working on github it can be added much quicker :slight_smile:

You’re not understanding the concept. It’s not about the batch size. Batch size does not matter as it still produces multiple emails for smaller companies that cannot afford dedicated servers to send multiple emails or more than one between certain times thus leading to email blocking/spam. What’s the point in sending a campaign of 1. What i’m saying is for those that don’t want to spend extra unnecessary money on mailchimp is use code that iterates and send 1 email every 8 seconds(Hostgator) for the 500 emails or whatever count you choose. Like the code I put from one of our programs, it gathers all the info such as the names and sends the emails out per our campaign 1 every 5-6 seconds for the next 1000 emails. with a pause at 500 for 5 minutes to purge(That part is not listed but used).

1 Like