function email_notify($check,$check_result,$subscription) { global $status_array; $user = new User($subscription->getUserId()); echo 'email plugin!'; $email = new fEmail(); // This sets up fSMTP to connect to the gmail SMTP server // with a 5 second timeout. Gmail requires a secure connection. $smtp = new fSMTP('smtp.gmail.com', 465, TRUE, 5); $smtp->authenticate('*****@*****.**', 'example'); $email->addRecipient($user->getEmail(), $user->getUsername()); // Set who the email is from $email->setFromEmail('*****@*****.**','Tattle'); // Set the subject include UTF-8 curly quotes $email->setSubject('Tattle : Alert for ' . $check->prepareName()); // Set the body to include a string containing UTF-8 $state = $status_array[$check_result->getStatus()]; $email->setHTMLBody("<p>$state Alert for {$check->prepareName()} </p><p>The check returned {$check_result->prepareValue()}</p><p>Warning Threshold is : ". $check->getWarn() . "</p><p>Error Threshold is : ". $check->getError() . '</p><p>View Alert Details : <a href="' . $fURL::getDomain() . '/' . CheckResult::makeURL('list',$check_result) . '">'.$check->prepareName()."</a></p>"); $email->setBody(" $state Alert for {$check->prepareName()} The check returned {$check_result->prepareValue()} Warning Threshold is : ". $check->getWarn() . " Error Threshold is : ". $check->getError() . " "); try { $message_id = $email->send($smtp); } catch ( fConnectivityException $e) { fCore::debug("email send failed",FALSE); } }
function email_plugin_notify($check,$check_result,$subscription,$alt_email=false) { global $status_array; $user = new User($subscription->getUserId()); $email = new fEmail(); // This sets up fSMTP to connect to the gmail SMTP server // with a 5 second timeout. Gmail requires a secure connection. $smtp = new fSMTP(sys_var('smtp_server'), sys_var('smtp_port'), TRUE, 5); $smtp->authenticate(sys_var('smtp_user'), sys_var('smtp_pass')); if ($alt_email) { $email_address = usr_var('alt_email',$user->getUserId()); } else { $email_address = $user->getEmail(); } $email->addRecipient($email_address, $user->getUsername()); // Set who the email is from $email->setFromEmail(sys_var('email_from'), sys_var('email_from_display')); // Set the subject include UTF-8 curly quotes $email->setSubject(str_replace('{check_name}', $check->prepareName(), sys_var('email_subject'))); // Set the body to include a string containing UTF-8 $state = $status_array[$check_result->getStatus()]; $email->setHTMLBody("<p>$state Alert for {$check->prepareName()} </p><p>The check returned {$check_result->prepareValue()}</p><p>Warning Threshold is : ". $check->getWarn() . "</p><p>Error Threshold is : ". $check->getError() . '</p><p>View Alert Details : <a href="' . fURL::getDomain() . '/' . CheckResult::makeURL('list',$check_result) . '">'.$check->prepareName()."</a></p>"); $email->setBody(" $state Alert for {$check->prepareName()} The check returned {$check_result->prepareValue()} Warning Threshold is : ". $check->getWarn() . " Error Threshold is : ". $check->getError() . " "); try { $message_id = $email->send($smtp); } catch ( fConnectivityException $e) { fCore::debug("email send failed",FALSE); } }
public function testClearRecipients() { $this->setExpectedException('fValidationException'); $token = $this->generateSubjectToken(); $email = new fEmail(); $email->setFromEmail('*****@*****.**'); $email->addRecipient(EMAIL_ADDRESS, 'Test User'); $email->addRecipient(EMAIL_ADDRESS, 'Test User 2'); $email->setSubject($token . ': Testing Simple Email'); $email->setBody('This is a simple test'); $email->clearRecipients(); $email->send(); }
/** * Sends an email or writes a file with messages generated during the page execution * * This method prevents multiple emails from being sent or a log file from * being written multiple times for one script execution. * * @internal * * @return void */ public static function sendMessagesOnShutdown() { $subject = self::compose('[%1$s] One or more errors or exceptions occured at %2$s', isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : php_uname('n'), date('Y-m-d H:i:s')); $messages = array(); if (self::$error_message_queue) { $message = join("\n\n", self::$error_message_queue); $messages[self::$error_destination] = $message; } if (self::$exception_message) { if (isset($messages[self::$exception_destination])) { $messages[self::$exception_destination] .= "\n\n"; } else { $messages[self::$exception_destination] = ''; } $messages[self::$exception_destination] .= self::$exception_message; } foreach ($messages as $destination => $message) { if (self::$show_context) { $message .= "\n\n" . self::generateContext(); } if (self::checkDestination($destination) == 'email') { if (self::$smtp_connection) { $email = new fEmail(); foreach (explode(',', $destination) as $recipient) { $email->addRecipient($recipient); } $email->setFromEmail(self::$smtp_from_email); $email->setSubject($subject); $email->setBody($message); $email->send(self::$smtp_connection); } else { mail($destination, $subject, $message); } } else { $handle = fopen($destination, 'a'); fwrite($handle, $subject . "\n\n"); fwrite($handle, $message . "\n\n"); fclose($handle); } } }
}else{ die("sendmail_error"); }*/ //$to=$_POST["email_to"]; $to = "*****@*****.**"; $to_name = "Ivan"; $subject = "Recomendación"; try { /* Envia email -------------------------------------------------------------- */ $message_html = $_POST["html"]; $message_plaintext = " "; $email = new fEmail(); $email->addRecipient($to, $_SESSION["name"]); // Destinatario $email->setFromEmail($_SESSION["username"], $_SESSION["name"]); // Remitente $email->setBounceToEmail($to); // En caso de que rebote llegara a la direccion ingresada. $email->setSubject($subject); // Asunto $email->setBody($message_plaintext); // Cuerpo del mensaje (texto plano) $email->setHTMLBody($message_html); // Cuerpo del mensaje (texto html) $email->send(); } catch (fValidationException $e) { $message = $e->getMessage(); die($message); } ?>
/** * Sends an email or writes a file with messages generated during the page execution * * This method prevents multiple emails from being sent or a log file from * being written multiple times for one script execution. * * @internal * * @return void */ public static function sendMessagesOnShutdown() { $messages = array(); if (self::$error_message_queue) { $message = join("\n\n", self::$error_message_queue); $messages[self::$error_destination] = $message; } if (self::$exception_message) { if (isset($messages[self::$exception_destination])) { $messages[self::$exception_destination] .= "\n\n"; } else { $messages[self::$exception_destination] = ''; } $messages[self::$exception_destination] .= self::$exception_message; } $hash = md5(join('', self::$significant_error_lines), TRUE); $hash = strtr(base64_encode($hash), '/', '-'); $hash = substr(rtrim($hash, '='), 0, 8); $first_file_line = preg_replace('#^.*[/\\\\](.*)$#', '\\1', reset(self::$significant_error_lines)); $subject = self::compose('[%1$s] %2$s error(s) beginning at %3$s {%4$s}', isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : php_uname('n'), count($messages), $first_file_line, $hash); foreach ($messages as $destination => $message) { if (self::$show_context) { $message .= "\n\n" . self::generateContext(); } if (self::checkDestination($destination) == 'email') { if (self::$smtp_connection) { $email = new fEmail(); foreach (explode(',', $destination) as $recipient) { $email->addRecipient($recipient); } $email->setFromEmail(self::$smtp_from_email); $email->setSubject($subject); $email->setBody($message); $email->send(self::$smtp_connection); } else { mail($destination, $subject, $message); } } else { $handle = fopen($destination, 'a'); fwrite($handle, $subject . "\n\n"); fwrite($handle, $message . "\n\n"); fclose($handle); } } }
/** * @dataProvider serverProvider */ public function testSendMultipleToCcBcc($server, $port, $secure, $username, $password) { $token = $this->generateSubjectToken(); $smtp = new fSMTP($server, $port, $secure, 10); if ($username) { $smtp->authenticate($username, $password); } $email = new fEmail(); $email->setFromEmail($username ? $username : '******'); $email->addRecipient(EMAIL_ADDRESS, 'Test User'); $email->addRecipient(str_replace('@', '_2@', EMAIL_ADDRESS), 'Test User 2'); $email->addCCRecipient(str_replace('@', '_3@', EMAIL_ADDRESS), 'Test User 3'); $email->addBCCRecipient(str_replace('@', '_4@', EMAIL_ADDRESS), 'Test User 4'); $email->setSubject($token . ': Testing Multiple Recipients'); $email->setBody('This is a test of sending multiple recipients'); $message_id = $email->send($smtp); $message = $this->findMessage($token, EMAIL_USER); $this->assertEquals($message_id, $message['headers']['message-id']); $this->assertEquals($username ? $username : '******', $message['headers']['from']['mailbox'] . '@' . $message['headers']['from']['host']); $this->assertEquals($token . ': Testing Multiple Recipients', $message['headers']['subject']); $this->assertEquals('This is a test of sending multiple recipients', trim($message['text'])); $message = $this->findMessage($token, str_replace('tests', 'tests_2', EMAIL_USER)); $this->assertEquals(array('personal' => 'Test User', 'mailbox' => 'tests', 'host' => 'flourishlib.com'), $message['headers']['to'][0]); $message = $this->findMessage($token, str_replace('tests', 'tests_3', EMAIL_USER)); $this->assertEquals(array('personal' => 'Test User 3', 'mailbox' => 'tests_3', 'host' => 'flourishlib.com'), $message['headers']['cc'][0]); $message = $this->findMessage($token, str_replace('tests', 'tests_4', EMAIL_USER)); $this->assertEquals(FALSE, isset($message['headers']['bcc'])); $smtp->close(); }
-------------------------------------------------------------- */ $message_html = "<b>Nombre:</b> " . $_POST["txtName"] . "<br />"; $message_html .= "<b>Email:</b> " . $_POST["txtEmail"] . "<br />"; $message_html .= "<b>Telefono:</b> " . $_POST["txtPhone"] . "<br />"; $message_html .= "<b>Consulta:</b>"; $message_html .= '<hr color="#093D6C">'; $message_html .= nl2br($_POST["txtConsult"]); $message_plaintext = "Nombre: " . $_POST["txtName"] . "\n"; $message_plaintext .= "Email: " . $_POST["txtEmail"] . "\n"; $message_plaintext .= "Telefono: " . $_POST["txtPhone"] . "\n"; $message_plaintext .= "Consulta:\n\n"; $message_plaintext .= $_POST["txtConsult"]; $email = new fEmail(); $email->addRecipient(EMAIL_CONTACT, EMAIL_CONTACT_NAME); // Destinatario $email->setFromEmail($_POST["txtEmail"], $_POST["txtName"]); // Remitente $email->setBounceToEmail(EMAIL_CONTACT); // En caso de que rebote llegara a la direccion ingresada. $email->setSubject(EMAIL_CONTACT_SUBJECT); // Asunto $email->setBody($message_plaintext); // Cuerpo del mensaje (texto plano) $email->setHTMLBody($message_html); // Cuerpo del mensaje (texto html) $email->send(); } catch (fValidationException $e) { echo $e->getMessage(); die; } die("ok");
echo "<p>" . $e->printMessage() . "</p>"; } catch (fSQLException $e) { echo "<p>An unexpected error occurred, please try again later</p>"; trigger_error($e); } } elseif (isset($_POST['sendtoken'])) { try { fRequest::validateCSRFToken($_POST['token']); $validator = new fValidation(); $validator->addRequiredFields('email'); $validator->validate(); $user = new User(array('email' => $_POST['email'])); $token = $user->getResetPasswordToken(); $email = new fEmail(); $email->addRecipient($user->getEmail()); $email->setFromEmail('*****@*****.**', 'London Hackspace'); $email->setSubject('London Hackspace Password Reset'); $name = $user->getFullName(); $email->setBody("Hi {$name},\n\nYou (or someone pretending to be you) requested a password reset for your\nLondon Hackspace account. To reset your password, go to this address:\n\nhttp://{$_SERVER['SERVER_NAME']}/passwordreset.php?token={$token}\n\nIf you don't want to reset your password, just ignore this email.\n\nCheers,\n\nThe London Hackspace email monkey\n"); $email->send(); echo "<p>An email has been sent to you with further instructions.</p>"; } catch (fNotFoundException $e) { ?> <p>No user exists with that email address. <a href="signup.php">Sign up</a>? Or <a href="passwordreset.php">try again</a>?</p> <?php } catch (fValidationException $e) { echo "<p>" . $e->printMessage() . "</p>"; } catch (fSQLException $e) { echo "<p>An unexpected error occurred, please try again later</p>"; trigger_error($e);
function notify_multiple_users($user_from, $recipients, $subject, $body) { $email = new fEmail(); // This sets up fSMTP to connect to the gmail SMTP server // with a 5 second timeout. Gmail requires a secure connection. $smtp = new fSMTP(sys_var('smtp_server'), sys_var('smtp_port'), sys_var('require_ssl') === 'true' ? TRUE : FALSE, 5); if (sys_var('require_auth') === 'true') { $smtp->authenticate(sys_var('smtp_user'), sys_var('smtp_pass')); } // Add the recipients foreach ($recipients as $rec) { $email->addRecipient($rec['mail'], $rec['name']); } // Set who the email is from $email->setFromEmail($user_from->getEmail(), $user_from->getUsername()); // Set the subject $email->setSubject($subject); // Set the body $email->setHTMLBody($body); $email->setBody($body); try { $message_id = $email->send($smtp); } catch (fConnectivityException $e) { fCore::debug($e, FALSE); fCore::debug("email send failed", FALSE); $e->printMessage(); $e->printTrace(); } }
/** * @dataProvider serverProvider */ public function testSendMultipleToCcBcc($server, $port, $secure, $username, $password) { $token = $this->generateSubjectToken(); $smtp = new fSMTP($server, $port, $secure, 5); if ($username) { $smtp->authenticate($username, $password); } $email = new fEmail(); $email->setFromEmail($username ? $username : '******'); $email->addRecipient(EMAIL_ADDRESS, 'Test User'); $email->addRecipient(str_replace('@', '_2@', EMAIL_ADDRESS), 'Test User 2'); $email->addCCRecipient(str_replace('@', '_3@', EMAIL_ADDRESS), 'Test User 3'); $email->addBCCRecipient(str_replace('@', '_4@', EMAIL_ADDRESS), 'Test User 4'); $email->setSubject($token . ': Testing Multiple Recipients'); $email->setBody('This is a test of sending multiple recipients'); $message_id = $email->send($smtp); $message = $this->findMessage($token, EMAIL_USER); $this->assertEquals($message_id, $message['headers']['Message-ID']); $this->assertEquals($username ? $username : '******', $message['headers']['From']); $this->assertEquals($token . ': Testing Multiple Recipients', $message['headers']['Subject']); $this->assertEquals('This is a test of sending multiple recipients', trim($message['plain'])); $message = $this->findMessage($token, str_replace('tests', 'tests_2', EMAIL_USER)); // It seems the windows imap extension doesn't support the personal part of an email address $is_windows = stripos(php_uname('a'), 'windows') !== FALSE; $this->assertEquals($is_windows ? '*****@*****.**' : '"Test User" <*****@*****.**>', $message['headers']['To']); $message = $this->findMessage($token, str_replace('tests', 'tests_3', EMAIL_USER)); $this->assertEquals($is_windows ? '*****@*****.**' : '"Test User 3" <*****@*****.**>', $message['headers']['Cc']); $message = $this->findMessage($token, str_replace('tests', 'tests_4', EMAIL_USER)); $this->assertEquals(FALSE, isset($message['headers']['Bcc'])); $smtp->close(); }