private function sendEmail($subject, $html, User $user, $campaignId, $count) { $mailgun = $this->getContainer()->get('mailgun'); $response = $mailgun->sendMessage(array('from' => '"Class Central\'s MOOC Tracker" <*****@*****.**>', 'to' => $user->getEmail(), 'subject' => $subject, 'html' => $html, 'o:campaign' => $campaignId)); if (!($response && $response->http_response_code == 200)) { // Failed return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_FAILED, $response && $response->http_response_body ? $response->http_response_body->message : "Mailgun error"); } return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_SUCCESS, "Course New Session notification sent for {$count} courses to user with id {$user->getId()}"); }
private function sendEmail($subject, $html, User $user) { $mailgun = $this->getContainer()->get('mailgun'); $response = $mailgun->sendMessage(array('from' => '"Dhawal Shah" <*****@*****.**>', 'to' => $user->getEmail(), 'subject' => $subject, 'html' => $html, 'o:campaign' => self::NEW_USER_FOLLOW_UP_CAMPAIGN_ID)); if (!($response && $response->http_response_code == 200)) { // Failed return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_FAILED, $response && $response->http_response_body ? $response->http_response_body->message : "Mailgun error"); } return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_SUCCESS, "Email sent"); }
private function sendEmail($subject, $html, User $user, $campaignId, $deliveryTime) { $mailgun = $this->getContainer()->get('mailgun'); $email = $user->getEmail(); $env = $this->getContainer()->getParameter('kernel.environment'); if ($env !== 'prod') { $email = $this->getContainer()->getParameter('test_email'); } try { $response = $mailgun->sendMessage(array('from' => '"Class Central" <*****@*****.**>', 'to' => $email, 'subject' => $subject, 'html' => $html, 'o:campaign' => $campaignId, 'o:deliverytime' => $deliveryTime)); if (!($response && $response->http_response_code == 200)) { // Failed return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_FAILED, $response && $response->http_response_body ? $response->http_response_body->message : "Mailgun error"); } } catch (\Exception $e) { // Probably a email validation error // Failed return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_FAILED, 'Mailgun Exception'); } return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_SUCCESS, "Email sent"); }
private function sendEmail($html, UserEntity $user, $numCourses, $campaignId, $deliveryTime) { $mailgun = $this->getContainer()->get('mailgun'); $email = $user->getEmail(); $env = $this->getContainer()->getParameter('kernel.environment'); if ($env !== 'prod') { $email = $this->getContainer()->getParameter('test_email'); } try { $response = $mailgun->sendMessage(array('from' => '"Class Central" <*****@*****.**>', 'to' => $email, 'subject' => $numCourses . ' brand new courses for you to join', 'html' => $html, 'o:campaign' => $campaignId, 'o:deliverytime' => $deliveryTime)); if (!($response && $response->http_response_code == 200)) { // Failed return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_FAILED, $response && $response->http_response_body ? $response->http_response_body->message : "Mailgun error"); } } catch (\Exception $e) { // Probably a email validation error // Failed return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_FAILED, 'Mailgun Exception - ' . $e->getMessage()); } return SchedulerJobStatus::getStatusObject(SchedulerJobStatus::SCHEDULERJOB_STATUS_SUCCESS, "Email sent for job " . self::NEW_COURSES_EMAIL_JOB_TYPE . " with user " . $user->getId()); }
public function unSubscribeUser(\ClassCentral\SiteBundle\Entity\Newsletter $newsLetter, \ClassCentral\SiteBundle\Entity\User $user) { return $this->unsubscribe($newsLetter->getCode(), $user->getEmail()); }
public function signup(\ClassCentral\SiteBundle\Entity\User $user, $emailVerification = true) { $em = $this->container->get('doctrine')->getManager(); $templating = $this->container->get('templating'); $mailgun = $this->container->get('mailgun'); $verifyTokenService = $this->container->get('verification_token'); $userSession = $this->container->get('user_session'); $user->setEmail(strtolower($user->getEmail())); // Normalize the email $password = $user->getPassword(); $user->setPassword($user->getHashedPassword($password)); // If the email has subscriptions to different newsletters, transfer it over to this user $emailEntity = $em->getRepository('ClassCentralSiteBundle:Email')->findOneByEmail($user->getEmail()); if ($emailEntity) { foreach ($emailEntity->getNewsletters() as $newsletter) { $user->addNewsletter($newsletter); } } $em->persist($user); $em->flush(); // Create user prefrences for the user $this->initPreferences($user); // Login the user $this->login($user); // Create a successfull signup notification $userSession->notifyUser(UserSession::FLASH_TYPE_SUCCESS, 'Account successfully created', "You can now build your own library of courses by adding them to <a href='/user/courses''>My Courses</a>", 30); // Send a welcome email but not in the test environment if ($this->container->getParameter('kernel.environment') != 'test') { $name = $user->getName() ? ucwords($user->getName()) : ""; $html = $templating->renderResponse('ClassCentralSiteBundle:Mail:welcome.html.twig', array('name' => $name, 'loginToken' => $this->getLoginToken($user), 'baseUrl' => $this->container->getParameter('baseurl'), 'utm' => array('medium' => Mailgun::UTM_MEDIUM, 'campaign' => 'new_user_welcome', 'source' => Mailgun::UTM_SOURCE_PRODUCT)))->getContent(); $mailgunResponse = $mailgun->sendIntroEmail($user->getEmail(), "'Dhawal Shah'<*****@*****.**>", "Welcome to Class Central, what else can you learn?", $html); if ($emailVerification) { // Send an email for verification $value = array('verify' => 1, 'email' => $user->getEmail()); $tokenEntity = $verifyTokenService->create($value, \ClassCentral\SiteBundle\Entity\VerificationToken::EXPIRY_1_YEAR); $html = $templating->renderResponse('ClassCentralSiteBundle:Mail:confirm.email.html.twig', array('token' => $tokenEntity->getToken()))->getContent(); $mailgunResponse = $mailgun->sendSimpleText($user->getEmail(), "*****@*****.**", "Please confirm your email", $html); // Send user a notification about this email $userSession->notifyUser(UserSession::FLASH_TYPE_NOTICE, 'Confirm your email address', "A confirmation email has been sent to <b>{$user->getEmail()}</b>. Click on the confirmation link in the email to activate your account", 60); } } return $user; }