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); } }
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); } }
/** * Resets the configuration of the class * * @internal * * @return void */ public static function reset() { self::$convert_crlf = FALSE; self::$fqdn = NULL; self::$popen_sendmail = FALSE; }
/** * Joins parsed emails into a comma-delimited string * * @param array $emails An array of emails split into personal, mailbox and host parts * @return string An comma-delimited list of emails */ private static function joinEmails($emails) { $output = ''; foreach ($emails as $email) { if ($output) { $output .= ', '; } if (!isset($email[0])) { $email[0] = !empty($email['personal']) ? $email['personal'] : ''; $email[2] = $email['mailbox']; $email[3] = !empty($email['host']) ? $email['host'] : ''; } $address = $email[2]; if (!empty($email[3])) { $address .= '@' . $email[3]; } $output .= fEmail::combineNameEmail($email[0], $address); } return $output; }
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() { $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); } } }
/** * 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); } } }
/** * @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(); }
if( $sendmail->send()){ die("sendmail_ok"); }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();
include_once '../flourish/init.php'; try { /* Envia email -------------------------------------------------------------- */ $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();
/** * Initiates the connection to the server * * @return void */ private function connect() { if ($this->connection) { return; } $fqdn = fEmail::getFQDN(); fCore::startErrorCapture(E_WARNING); $host = $this->secure ? 'tls://' . $this->host : $this->host; $this->connection = fsockopen($host, $this->port, $error_int, $error_string, $this->timeout); foreach (fCore::stopErrorCapture('#ssl#i') as $error) { throw new fConnectivityException('There was an error connecting to the server. A secure connection was requested, but was not available. Try a non-secure connection instead.'); } if (!$this->connection) { throw new fConnectivityException('There was an error connecting to the server'); } stream_set_timeout($this->connection, $this->timeout); $response = $this->read('#^220 #'); if (!$this->find($response, '#^220[ -]#')) { throw new fConnectivityException('Unknown SMTP welcome message, %1$s, from server %2$s on port %3$s', join("\r\n", $response), $this->host, $this->port); } // Try sending the ESMTP EHLO command, but fall back to normal SMTP HELO $response = $this->write('EHLO ' . $fqdn, '#^250 #m'); if ($this->find($response, '#^500#')) { $response = $this->write('HELO ' . $fqdn, 1); } // If STARTTLS is available, use it if (!$this->secure && extension_loaded('openssl') && $this->find($response, '#^250[ -]STARTTLS#')) { $response = $this->write('STARTTLS', '#^220 #'); $affirmative = $this->find($response, '#^220[ -]#'); if ($affirmative) { do { if (isset($res)) { sleep(0.1); } $res = stream_socket_enable_crypto($this->connection, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT); } while ($res === 0); } if (!$affirmative || $res === FALSE) { throw new fConnectivityException('Error establishing secure connection'); } $response = $this->write('EHLO ' . $fqdn, '#^250 #m'); } $this->max_size = 0; if ($match = $this->find($response, '#^250[ -]SIZE\\s+(\\d+)$#')) { $this->max_size = $match[0][1]; } $this->pipelining = (bool) $this->find($response, '#^250[ -]PIPELINING$#'); $auth_methods = array(); if ($match = $this->find($response, '#^250[ -]AUTH[ =](.*)$#')) { $auth_methods = array_map('strtoupper', explode(' ', $match[0][1])); } if (!$auth_methods || !$this->username) { return; } if (in_array('DIGEST-MD5', $auth_methods)) { $response = $this->write('AUTH DIGEST-MD5', 1); $this->handleErrors($response); $match = $this->find($response, '#^334 (.*)$#'); $challenge = base64_decode($match[0][1]); preg_match_all('#(?<=,|^)(\\w+)=("[^"]+"|[^,]+)(?=,|$)#', $challenge, $matches, PREG_SET_ORDER); $request_params = array(); foreach ($matches as $_match) { $request_params[$_match[1]] = $_match[2][0] == '"' ? substr($_match[2], 1, -1) : $_match[2]; } $missing_qop_auth = !isset($request_params['qop']) || !in_array('auth', explode(',', $request_params['qop'])); $missing_nonce = empty($request_params['nonce']); if ($missing_qop_auth || $missing_nonce) { throw new fUnexpectedException('The SMTP server %1$s on port %2$s claims to support DIGEST-MD5, but does not seem to provide auth functionality', $this->host, $this->port); } if (!isset($request_params['realm'])) { $request_params['realm'] = ''; } // Algorithm from http://www.ietf.org/rfc/rfc2831.txt $realm = $request_params['realm']; $nonce = $request_params['nonce']; $cnonce = fCryptography::randomString('32', 'hexadecimal'); $nc = '00000001'; $digest_uri = 'smtp/' . $this->host; $a1 = md5($this->username . ':' . $realm . ':' . $this->password, TRUE) . ':' . $nonce . ':' . $cnonce; $a2 = 'AUTHENTICATE:' . $digest_uri; $response = md5(md5($a1) . ':' . $nonce . ':' . $nc . ':' . $cnonce . ':auth:' . md5($a2)); $response_params = array('charset=utf-8', 'username="******"', 'realm="' . $realm . '"', 'nonce="' . $nonce . '"', 'nc=' . $nc, 'cnonce="' . $cnonce . '"', 'digest-uri="' . $digest_uri . '"', 'response=' . $response, 'qop=auth'); $response = $this->write(base64_encode(join(',', $response_params)), 2); } elseif (in_array('CRAM-MD5', $auth_methods)) { $response = $this->write('AUTH CRAM-MD5', 1); $match = $this->find($response, '#^334 (.*)$#'); $challenge = base64_decode($match[0][1]); $response = $this->write(base64_encode($this->username . ' ' . fCryptography::hashHMAC('md5', $challenge, $this->password)), 1); } elseif (in_array('LOGIN', $auth_methods)) { $response = $this->write('AUTH LOGIN', 1); $this->write(base64_encode($this->username), 1); $response = $this->write(base64_encode($this->password), 1); } elseif (in_array('PLAIN', $auth_methods)) { $response = $this->write('AUTH PLAIN ' . base64_encode($this->username . "" . $this->username . "" . $this->password), 1); } if ($this->find($response, '#^535[ -]#')) { throw new fValidationException('The username and password provided were not accepted for the SMTP server %1$s on port %2$s', $this->host, $this->port); } if (!array_filter($response)) { throw new fConnectivityException('No response was received for the authorization request'); } }
exit; } 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); } } 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) {
public function actionHelp() { $model = new fEmail(); if (isset($_POST['fEmail'])) { $model->attributes = $_POST['fEmail']; if ($model->validate()) { EmailComponent::getInstance()->sendEmail('*****@*****.**', $model->subject, $model->body, 'ssl'); Yii::app()->user->setFlash('success', '<strong>Great!</strong> Your Message has been sent...'); $this->redirect(array('/menu')); } } $this->render('help', array('model' => $model)); }
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(); }
/** * Initializes fEmail for creating message ids * * @return fEmail */ public function __construct() { if (self::$local_hostname !== NULL) { return; } if (isset($_ENV['HOST'])) { self::$local_hostname = $_ENV['HOST']; } if (strpos(self::$local_hostname, '.') === FALSE && isset($_ENV['HOSTNAME'])) { self::$local_hostname = $_ENV['HOSTNAME']; } if (strpos(self::$local_hostname, '.') === FALSE) { self::$local_hostname = php_uname('n'); } if (strpos(self::$local_hostname, '.') === FALSE && !in_array('exec', explode(',', ini_get('disable_functions'))) && !ini_get('safe_mode') && !ini_get('open_basedir')) { if (fCore::checkOS('linux')) { self::$local_hostname = trim(shell_exec('hostname --fqdn')); } elseif (fCore::checkOS('windows')) { $output = shell_exec('ipconfig /all'); if (preg_match('#DNS Suffix Search List[ .:]+([a-z0-9_.-]+)#i', $output, $match)) { self::$local_hostname .= '.' . $match[1]; } } elseif (fCore::checkOS('bsd', 'osx') && file_exists('/etc/resolv.conf')) { $output = file_get_contents('/etc/resolv.conf'); if (preg_match('#^domain ([a-z0-9_.-]+)#im', $output, $match)) { self::$local_hostname .= '.' . $match[1]; } } } }