File: //home/awaldron/_domains/api.alanwaldron.com/v1/mail.php
<?php
//**********************************************************************************************************//
// Method: GET
// Endpoint: read
// Params:
function get_v1_mail_read1( $args, $body, $uid, $is_admin, $db ) {
$db->query("UPDATE committee SET read1=read1+1 WHERE id=".$args[0]);
$img = '/home/awaldron/_domains/api.alanwaldron.com/aw-logo.png';
header('Content-Type: image/png');
readfile($img);
}
//**********************************************************************************************************//
// Method: GET
// Endpoint: send
// Params: subject, body
function get_v1_mail_send1( $args, $body, $uid, $is_admin, $db ) {
$rules = [
'from' => 'req',
'to' => 'req',
'subject' => 'req',
'body' => 'req'
];
$token_required = true;
$members = qSet( $db, "SELECT * FROM committee" );
$errors = [];
$testUser = array( 'fname'=>'Alan', 'id'=>92 );
$i=0;
foreach ($members as $m) {
if (!empty($m['email'])) {
try {
$i++;
$email = get_email_template( $m );
//echo $email; exit;
$mail = new PHPMailer\PHPMailer\PHPMailer(true);
$mail->isSMTP();
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Host = "mail.smtp2go.com";
$mail->Port = "2525";
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Username = "pennhillscdc";
$mail->Password = "xVnXrJGR76RMycPL";
$mail->setFrom('alan@waldroninteractive.com', "Alan Waldron");
$mail->AddReplyTo('alan@waldroninteractive.com', "Alan Waldron");
$mail->AddAddress($m['email'], $m['fname'].' '.$m['lname']);
$mail->isHTML(true);
$mail->Subject = 'Alan Waldron for Penn Hills Council';
$mail->Body = $email;
$mail->send();
} catch (Exception $e) {
$errors[] = $mail->ErrorInfo;
}
}
}
response(200,['success'=>true, 'message'=>'All '.$i.' emails sent successfully']);
}
//**********************************************************************************************************//
// Method: GET
// Endpoint: send
// Params: subject, body
function get_v1_mail_log( $args, $body, $uid, $is_admin, $db ) {
print_r($args);
$db->query("UPDATE committee SET endorse1=".$args[1]." WHERE id=".$args[0]);
if ($args[1]==1) {
header("Location: http://campaign.alanwaldron.com/thankyou.php");
} else {
header("Location: http://campaign.alanwaldron.com/sorry.php");
}
}