static function sendContactEmail($app) { $post = $app->request->post(); self::validateParameters($app, $post); // Setup mailer for sending message $mail = ApiMailer::getPhpMailer(); // Add Recipient - include name if it was sent if (!$recipientName || $recipientName === '') { $mail->addAddress($recipientEmail); } else { $mail->addAddress($recipientEmail, $recipientName); } // Retrieve template $emailTemplate = self::selectEmailTemplate($templateId); if (!$emailTemplate) { self::logMailError(LOG_ERR, "ERROR RETRIEVING EMAIL TEMPLATE, templateId <{$templateId}>"); return array('error' => true, 'msg' => "Error generating email <{$templateId}>"); } // If a from email is set if ($emailTemplate->fromEmail) { $mail->setFrom($emailTemplate->fromEmail, $emailTemplate->fromName); } // If a reply to email is set if ($emailTemplate->replyEmail) { $mail->setFrom($emailTemplate->replyEmail, $emailTemplate->replyName); } // Substitute parameters into template // Template substitution is for parms named !@{NUMBER}@!, i.e., !@0@!, !@1@!, etc // Subject Substituion $subject = $emailTemplate->subject; for ($index = 0; $index < count($subjectParams); $index++) { $subject = str_replace("!@{$index}@!", $subjectParams[$index], $subject); } $mail->Subject = $subject; // Body Substitution $bodyHtml = $emailTemplate->bodyHtml; $bodyPlain = $emailTemplate->bodyPlain; for ($index = 0; $index < count($bodyParams); $index++) { $bodyHtml = str_replace("!@{$index}@!", $bodyParams[$index], $bodyHtml); $bodyPlain = str_replace("!@{$index}@!", $bodyParams[$index], $bodyPlain); } $mail->Body = $bodyHtml; $mail->AltBody = $bodyPlain; if ($mail->send()) { // log the success self::logMailError(LOG_INFO, "EMAIL SUCCESS\n Template Id:<{$templateId}> Sender: <{$emailTemplate->replyEmail}, {$emailTemplate->replyName}> Recipient: <{$recipientEmail}, {$recipientName}> Subject: <{$subject}> Body: <{$bodyPlain}>"); return !$recipientName || $recipientName === '' ? array('error' => false, 'msg' => "Success! Email Sent to \"{$recipientEmail}\"") : array('error' => false, 'msg' => "Success! Email Sent to \"{$recipientEmail}, {$recipientName}\""); } else { // log the error self::logMailError(LOG_ERR, "EMAIL FAILURE\nError <{$mail->ErrorInfo}>/n Template Id:<{$templateId}> Sender: <{$emailTemplate->replyEmail}, {$emailTemplate->replyName}> Recipient: <{$recipientEmail}, {$recipientName}> Subject: <{$subject}> Body: <{$bodyPlain}>"); return !$recipientName || $recipientName === '' ? array('error' => true, 'msg' => "Unknown Error: Error sending email to \"{$recipientEmail}, {$recipientName}\"") : array('error' => true, 'msg' => "Unknown Error: Error sending email to \"{$recipientEmail}, {$recipientName}\""); } if ($sent) { return $app->render(200, array('msg' => "Player invite sent to '{$post['email']}'.")); } else { return $app->render(400, array('msg' => 'Could not send player invite.')); } }
static function facebookSignup($app) { $result = AuthControllerFacebook::signup($app); if ($result['registered']) { AuthHooks::signup($app, $result); if (isset($result['user']->teams[0])) { ApiMailer::sendWebsiteSignupJoinTeamConfirmation($result['user']->teams[0]->name, $result['user']->email, "{$result['user']->nameFirst} {$result['user']->nameLast}"); } else { ApiMailer::sendWebsiteSignupConfirmation($result['user']->email, "{$result['user']->nameFirst} {$result['user']->nameLast}"); } return $app->render(200, $result); } else { return $app->render(400, $result); } }
static function silentlySendTeamInviteEmail($teamId, $teamName, $playerEmail, $playerId = NULL, $playerName = '') { // Try to set the players user id if the email exists in the DB $foundId = is_null($playerId) ? EmailData::selectUserIdByEmail($playerEmail) : $playerId; $userId = !$foundId ? NULL : $foundId; $token = self::makeInviteToken(); $saved = EmailData::insertTeamInvite(array(":token" => $token, ":team_id" => $teamId, ":user_id" => $userId, ":name_first" => NULL, ":name_last" => NULL, ":email" => $playerEmail, ":phone" => NULL, ":created_user_id" => APIAuth::getUserId())); if (!$saved) { return 'Could not create invite. Check your parameters and try again.'; } if (is_null($userId)) { return ApiMailer::sendTeamInviteNewUser($token, $teamName, $playerEmail, $playerName); } else { return ApiMailer::sendTeamInviteRegisteredUser($token, $teamName, $playerEmail, $playerName); } }
<?php namespace API; require_once dirname(dirname(__FILE__)) . "/vendor/autoload.php"; // Composer components require_once dirname(dirname(__FILE__)) . "/services/api.mailer.php"; // Mailer Service date_default_timezone_set('America/New_York'); $now = date('l jS \\of F Y h:i:s A'); print_r(\API\ApiMailer::sendSystemTest("Timestamp: {$now}", "*****@*****.**", "RC AngularSeed Email-Test"));