Skip to content

Instantly share code, notes, and snippets.

@i-tabu
Created July 14, 2016 14:33
Show Gist options
  • Save i-tabu/1cbe555d6f6aa5c3b4ddba20a30fd087 to your computer and use it in GitHub Desktop.
Save i-tabu/1cbe555d6f6aa5c3b4ddba20a30fd087 to your computer and use it in GitHub Desktop.
<?php
/**
CREATE TABLE `invitees` (
`email` varchar(255) NOT NULL,
`name` varchar(255) NOT NULL,
`sent` tinyint(1) NOT NULL DEFAULT '0',
`remarks` text NOT NULL,
`group` varchar(15) DEFAULT NULL,
`lastname` varchar(255) DEFAULT NULL,
PRIMARY KEY (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `invitees` (`email`,`name`) values ('[email protected]','name');
*/
require_once __DIR__.'/vendor/autoload.php';
use PepipostAPIV10Lib\Controllers\Email;
$email = new Email();
//Configuration
define('DB_HOST','<your_host_name>');
define('DB_USER','<your_db_user>');
define('DB_PASS','<your_db_password>');
define('DB_NAME','<your_db_name>');
define('API_KEY','<your_pepipost_apikey>');
define('FROM_ADDRESS','<your_email_address>');
define('FROM_NAME','<your_name>');
//Get teh data
$dbh = connect_db(DB_HOST, DB_NAME, DB_USER, DB_PASS);
$rs = mysql_query('select * from invitees where sent = 0 ');
$data = array(
'api_key' => API_KEY,
//'recipients' => array('[email protected]'),
'email_details' => array(
'content' => trim(file_get_contents('content.html')),
'from' => FROM_ADDRESS,
'subject' => 'You are invited to my Wedding on 8th May 2016 (between 7pm to 10 pm @ Thane)',
'fromname' => FROM_NAME,
//'replytoid' => '<your_replyto_id_if_any>',
),
'files' => array(
'tabrez-wedding-card-cover.png' => base64_encode(trim(file_get_contents('attachments/compressed-small/tabrez-wedding-card-cover-min.png'))),
'tabrez-wedding-insidepage.png' => base64_encode(trim(file_get_contents('attachments/compressed-small/tabrez-wedding-insidepage-min.png'))),
),
);
while($row = mysql_fetch_assoc($rs)){
//print_r($row);
$data['recipients'][] = $row['email'];
$data['attributes']['NAME'][] = $row['name'];
}
try {
$response = $email->sendJson( $data );
if(empty($response->errorcode)){
print "Email sent successfully.\n";
}
else {
print "Email sent Failed.\n";
print "errormessage(" . $response->errormessage . ") \n";
print "errorcode(" . $response->errorcode . ").\n";
}
}
catch(Exception $e){
print 'Call failed due to unhandled exception/error('. $e->getMessage().')'."\n";
}
function connect_db($db_host, $db_name, $db_user, $db_pass) {
// Connecting the the local MySQL DB engine
$db = mysql_connect($db_host, $db_user, $db_pass) or die("Could not connect to database. MySQL Error:" . mysql_error());
// Connecting to the database
mysql_select_db($db_name,$db) or die('Not able to select Db. MySQL Error:'.mysql_error());
return $db;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment