Page 1 of 1

To send email on some future time

Posted: Mon Mar 10, 2014 8:52 am
by kamran431
I am making a php script which fetches the data of the records from the database whose sending date and time has been reached, and then sends email to those records.
I want to perform the following steps.
Step 1: get the communication records from the database whose time has been reached.
Step 2: run the loop of above and get the email addresses.
Step 3: run the loop of email addresses and send emails.
This is my php script.

Code: Select all

<?php
	include('iSDK/src/isdk.php');
	$myApp = new iSDK();
	// Test Connnection
	if ($myApp->cfgCon("connectionName")) {
		echo "Connected...";
	} else {
		echo "Not Connected...";
	}
	$query = mysql_query('SELECT * FROM emails where senddate <= NOW() AND STATUS = "pending"');
	$emailaddress= array();
	while ($result = mysql_fetch_assoc($query))
	{
		$emailaddress[] = $result['email'];
		$count = mysql_num_rows($query);
		if($result)
		{
			for($i=0; $i<$count; $i++){
		    $conDat = array('Email' => $emailaddress[$i]);
		    $conID = $myApp->addCon($conDat);
		    $clist = array($conID);
		    $email = $myApp->sendEmail($clist, 'sender@example.com', '~Contact.Email~', 'ccAddresses', 'bccAddresses', 'contentType', 'Subject', 'htmlBody', 'txtBody');
	}
		}
}
?>
What changes should be made in my code? is it going well?

Re: To send email on some future time

Posted: Mon Mar 10, 2014 11:07 am
by Christopher
Looks good. I assume it is sending emails. You need to UPDATE the status to "sent" so it will not resend emails.