Exemplo n.º 1
0
 /**
  * Tests for success at creating the object.
  */
 public function testCreate()
 {
     $test_text = 'test text';
     $t = new Message();
     $t->setText($test_text);
     $this->assertTrue($t instanceof Message);
     $this->assertEquals($t->__toString(), $test_text);
 }
Exemplo n.º 2
0
    /**
     * Send an email using a Transactional email service
     * or native PHP as a fallback.
     *
     * @param array  $attributes  A list of attributes for sending
     * @return bool on success
     */
    public static function send($attributes = array())
    {
        /*
        |--------------------------------------------------------------------------
        | Required attributes
        |--------------------------------------------------------------------------
        |
        | We first need to ensure we have the minimum fields necessary to send
        | an email.
        |
        */
        $required = array_intersect_key($attributes, array_flip(self::$required));

        if (count($required) >= 3) {

            /*
            |--------------------------------------------------------------------------
            | Load handler from config
            |--------------------------------------------------------------------------
            |
            | We check the passed data for a mailer + key first, and then fall back
            | to the global Statamic config.
            |
            */
            $email_handler     = array_get($attributes, 'email_handler', Config::get('email_handler', null));
            $email_handler_key = array_get($attributes, 'email_handler_key', Config::get('email_handler_key', null));

            if (in_array($email_handler, self::$email_handlers) && $email_handler_key) {

                /*
                |--------------------------------------------------------------------------
                | Initialize Stampie
                |--------------------------------------------------------------------------
                |
                | Stampie provides numerous adapters for popular email handlers, such as
                | Mandrill, Postmark, and SendGrid. Each is written as an abstract
                | interface in an Adapter Pattern.
                |
                */
                $mailer = self::initializeEmailHandler($email_handler, $email_handler_key);

                /*
                |--------------------------------------------------------------------------
                | Initialize Message class
                |--------------------------------------------------------------------------
                |
                | The message class is an implementation of the Stampie MessageInterface
                |
                */
                $email = new Message($attributes['to']);

                /*
                |--------------------------------------------------------------------------
                | Set email attributes
                |--------------------------------------------------------------------------
                |
                | I hardly think this requires much explanation.
                |
                */
                $email->setFrom($attributes['from']);

                $email->setSubject($attributes['subject']);

                if (isset($attributes['text'])) {
                    $email->setText($attributes['text']);
                }

                if (isset($attributes['html'])) {
                    $email->setHtml($attributes['html']);
                }

                if (isset($attributes['cc'])) {
                    $email->setCc($attributes['cc']);
                }

                if (isset($attributes['bcc'])) {
                    $email->setBcc($attributes['bcc']);
                }

                if (isset($attributes['headers'])) {
                    $email->setHeaders($attributes['headers']);
                }

                $mailer->send($email);

                return true;

            } else {

                /*
                |--------------------------------------------------------------------------
                | Native PHP Mail
                |--------------------------------------------------------------------------
                |
                | We're utilizing the popular PHPMailer class to handle the messy
                | email headers and do-dads. Emailing from PHP in general isn't the best
                | idea known to man, so this is really a lackluster fallback.
                |
                */
            try {
                $email = new PHPMailer(true);

                // SMTP
                if ($attributes['smtp'] = array_get($attributes, 'smtp', Config::get('smtp'))) {
                    
                    $email->isSMTP();

                    if ($smtp_host = array_get($attributes, 'smtp:host', false)) {
                        $email->Host = $smtp_host;
                    }

                    if ($smtp_secure = array_get($attributes, 'smtp:secure', false)) {
                        $email->SMTPSecure = $smtp_secure;
                    }

                    if ($smtp_port = array_get($attributes, 'smtp:port', false)) {
                        $email->Port = $smtp_port;
                    }

                    if (array_get($attributes, 'smtp:auth', false) === TRUE) {
                        $email->SMTPAuth = TRUE;
                    }

                    if ($smtp_username = array_get($attributes, 'smtp:username', false)) {
                        $email->Username = $smtp_username;
                    }

                    if ($smtp_password = array_get($attributes, 'smtp:password', false)) {
                        $email->Password = $smtp_password;
                    }

                // SENDMAIL
                } elseif (array_get($attributes, 'sendmail', false)) {
                    $email->isSendmail();

                // PHP MAIL
                } else {
                    $email->isMail();
                }

                $email->CharSet = 'UTF-8';

                $from_parts = self::explodeEmailString($attributes['from']);
                $email->setFrom($from_parts['email'], $from_parts['name']);

                $to = Helper::ensureArray($attributes['to']);
                foreach ($to as $to_addr) {
                    $to_parts = self::explodeEmailString($to_addr);
                    $email->addAddress($to_parts['email'], $to_parts['name']);
                }

                $email->Subject  = $attributes['subject'];

                if (isset($attributes['html'])) {
                    $email->msgHTML($attributes['html']);

                    if (isset($attributes['text'])) {
                        $email->AltBody = $attributes['text'];
                    }

                } elseif (isset($attributes['text'])) {
                    $email->msgHTML($attributes['text']);
                }

                if (isset($attributes['cc'])) {
                    $cc = Helper::ensureArray($attributes['cc']);
                    foreach ($cc as $cc_addr) {
                        $cc_parts = self::explodeEmailString($cc_addr);
                        $email->addCC($cc_parts['email'], $cc_parts['name']);
                    }                    
                }

                if (isset($attributes['bcc'])) {
                    $bcc = Helper::ensureArray($attributes['bcc']);
                    foreach ($bcc as $bcc_addr) {
                        $bcc_parts = self::explodeEmailString($bcc_addr);
                        $email->addBCC($bcc_parts['email'], $bcc_parts['name']);
                    }      
                }

                $email->send();

                } catch (phpmailerException $e) {
                    echo $e->errorMessage(); //error messages from PHPMailer
                    Log::error($e->errorMessage(), 'core', 'email');
                } catch (Exception $e) {
                    echo $e->getMessage();
                    Log::error($e->getMessage(), 'core', 'email');
                }

            }
        }

        return false;
    }
Exemplo n.º 3
0
Arquivo: email.php Projeto: nob/joi
 /**
  * Send an email using a Transactional email service
  * or native PHP as a fallback.
  *
  * @param array  $attributes  A list of attributes for sending
  * @return bool on success
  */
 public static function send($attributes = array())
 {
     /*
     |--------------------------------------------------------------------------
     | Required attributes
     |--------------------------------------------------------------------------
     |
     | We first need to ensure we have the minimum fields necessary to send
     | an email.
     |
     */
     $required = array_intersect_key($attributes, array_flip(self::$required));
     if (count($required) >= 3) {
         /*
         |--------------------------------------------------------------------------
         | Load handler from config
         |--------------------------------------------------------------------------
         |
         | We check the passed data for a mailer + key first, and then fall back
         | to the global Statamic config.
         |
         */
         $email_handler = array_get($attributes, 'email_handler', Config::get('email_handler', null));
         $email_handler_key = array_get($attributes, 'email_handler_key', Config::get('email_handler_key', null));
         if (in_array($email_handler, self::$email_handlers) && $email_handler_key) {
             /*
             |--------------------------------------------------------------------------
             | Initialize Stampie
             |--------------------------------------------------------------------------
             |
             | Stampie provides numerous adapters for popular email handlers, such as
             | Mandrill, Postmark, and SendGrid. Each is written as an abstract
             | interface in an Adapter Pattern.
             |
             */
             $mailer = self::initializeEmailHandler($email_handler, $email_handler_key);
             /*
             |--------------------------------------------------------------------------
             | Initialize Message class
             |--------------------------------------------------------------------------
             |
             | The message class is an implementation of the Stampie MessageInterface
             |
             */
             $email = new Message($attributes['to']);
             /*
             |--------------------------------------------------------------------------
             | Set email attributes
             |--------------------------------------------------------------------------
             |
             | I hardly think this requires much explanation.
             |
             */
             $email->setFrom($attributes['from']);
             $email->setSubject($attributes['subject']);
             if (isset($attributes['text'])) {
                 $email->setText($attributes['text']);
             }
             if (isset($attributes['html'])) {
                 $email->setHtml($attributes['html']);
             }
             if (isset($attributes['cc'])) {
                 $email->setCc($attributes['cc']);
             }
             if (isset($attributes['bcc'])) {
                 $email->setBcc($attributes['bcc']);
             }
             if (isset($attributes['headers'])) {
                 $email->setHeaders($attributes['headers']);
             }
             $mailer->send($email);
             return true;
         } else {
             /*
             |--------------------------------------------------------------------------
             | Native PHP Mail
             |--------------------------------------------------------------------------
             |
             | We're utilizing the popular PHPMailer class to handle the messy
             | email headers and do-dads. Emailing from PHP in general isn't the best
             | idea known to man, so this is really a lackluster fallback.
             |
             */
             $email = new PHPMailer(true);
             $email->IsMAIL();
             $email->CharSet = 'UTF-8';
             $email->AddAddress($attributes['to']);
             $email->From = $attributes['from'];
             $email->FromName = $attributes['from'];
             $email->Subject = $attributes['subject'];
             if (isset($attributes['text'])) {
                 $email->AltBody = $attributes['text'];
             }
             if (isset($attributes['html'])) {
                 $email->Body = $attributes['html'];
                 $email->IsHTML(true);
             }
             if (isset($attributes['cc'])) {
                 $email->AddCC($attributes['cc']);
             }
             if (isset($attributes['bcc'])) {
                 $email->AddBCC($attributes['bcc']);
             }
             if ($email->Send()) {
                 return true;
             }
         }
     }
     return false;
 }
Exemplo n.º 4
0
function message_submit()
{
    // get global user object
    global $user;
    // protect from unauthorized access
    if (!isset($user) || !isset($_POST['formMessageSubmit']) || !isset($_POST['formMessage'])) {
        logout();
        die;
    }
    // get message data from $_POST
    $title = filter_input(INPUT_POST, 'messageTitle');
    $text = filter_input(INPUT_POST, 'messageText');
    $time_now = date("Y-m-d H:i:s");
    // send mail
    send_mail($title, $text);
    // set message object
    $message = new Message();
    $message->setIsActive(1);
    $message->setCreatedOn($time_now);
    $message->setLastEditedOn($time_now);
    $message->setUser($user->getId());
    $message->setTitle($title);
    $message->setText($text);
    // store message object in db
    $message->store_in_db();
    // set message cookie
    $cookie_key = 'msg';
    $cookie_value = 'Благодарим Ви за съобщението!';
    setcookie($cookie_key, $cookie_value, time() + 1);
    header('location:' . ROOT_DIR . '?page=survey_role');
}
Exemplo n.º 5
0
                $Statement = $Database->prepare("UPDATE users SET thumbnail = ? WHERE id = ?");
                $Statement->execute(array($thumbnailUrl, $user["id"]));
                header("Location: " . $_SERVER["REQUEST_URI"]);
            } catch (Exception $e) {
                echo $e->getMessage();
            }
        }
    }
}
//Process the message reply form
if (isset($_POST["send_reply" . $messageCount])) {
    $Message = new Message($user["id"], $Database);
    //Instantiate the message class
    try {
        $Message->setReciever($_POST["sid" . $messageCount]);
        $Message->setText($_POST["message_text" . $messageCount]);
        $Message->send();
    } catch (Exception $e) {
        echo $e->getMessage();
    }
    header("Location: " . $_SERVER["REQUEST_URI"]);
}
#####################################################
/**
 * Displays the html of the page based on the page settings
 */
if (!empty($user)) {
    //If the user is logged in
    require $baseDir . 'includes/templates/page_header.php';
} else {
    //If the user isn't logged in
Exemplo n.º 6
0
<?php

session_start();
require_once '../resources/require.php';
// dodoaje nową wiadomość do bazy, uzupełnia komunikat o wysłaniu bądź błędzie
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['verify_post'])) {
    if (trim($_POST['message_text']) != '') {
        $message = new Message($mysqli);
        $message->setReceiverId($_POST['receiver_id']);
        $message->setSenderId($_SESSION['user_id']);
        $message->setText($_POST['message_text']);
        $message->setStatus(0);
        $message->setCreationDate(date("Y-m-d H:i:s"));
        if (!$message->create()) {
            $info = 'Nie udało się wysłać wiadomości. Spróbuj ponownie.';
        } else {
            $info = 'Wiadomość została wysłana.';
        }
    } else {
        $info = 'Uzupełnij treść wiadomości.';
    }
}
?>
<!DOCTYPE html>
<html lang="pl-PL">

<title>Twitter | Wyślij wiadomość </title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
Exemplo n.º 7
0
 /**
  * Set text part of the message.
  *
  * @param  string $text
  * @return Mail
  */
 public function setText($text)
 {
     $this->message->setText($text);
     return $this;
 }
Exemplo n.º 8
0
 public function inbox($delete = true)
 {
     $dataArray = $this->getAuthData();
     $dataArray['action'] = 'inbox';
     $response = new \SimpleXMLElement($this->getAnswer((string) $this->httpClient->get($this->apiScript, ['query' => array_merge($dataArray, ['delete' => $delete ? 1 : 0])])->getBody()));
     if ((int) $response->err > 0) {
         throw new IOException('Sending error ' . (int) $response->err . ': ' . $this->getErrorMessage((int) $response->err), (int) $response->err);
     }
     $list = [];
     foreach ($response->inbox->delivery_sms as $it) {
         if (empty($it)) {
             continue;
         }
         $message = new Message();
         $message->setNumber((string) $it->number);
         $message->setText((string) $it->message);
         $message->setDate(\DateTime::createFromFormat('Ymd His', str_replace('T', ' ', $it->time)));
         $list[] = $message;
     }
     return $list;
 }
Exemplo n.º 9
0
 public function parseMessage($messageObject)
 {
     $message = new Message();
     $message->setMessageId($messageObject->message_id);
     $message->setFrom($this->parseUser($messageObject->from));
     $message->setDate($messageObject->date);
     // TODO: test it for User and GroupChat types
     $message->setChat($this->parseChat($messageObject->chat));
     if (property_exists($messageObject, 'forward_from')) {
         $message->setForwardFrom($this->parseUser($messageObject->forward_from));
     }
     if (property_exists($messageObject, 'forward_date')) {
         $message->setForwardDate($messageObject->forward_date);
     }
     // TODO: reply to message attribute
     if (property_exists($messageObject, 'text')) {
         $message->setText($messageObject->text);
     }
     if (property_exists($messageObject, 'audio')) {
         $message->setAudio($this->parseAudio($messageObject->audio));
     }
     if (property_exists($messageObject, 'document')) {
         $message->setDocument($this->parseDocument($messageObject->document));
     }
     if (property_exists($messageObject, 'photo')) {
         $message->setPhoto($this->parsePhotoSize($messageObject->photo));
     }
     if (property_exists($messageObject, 'sticker')) {
         $message->setSticker($this->parseSticker($messageObject->sticker));
     }
     if (property_exists($messageObject, 'video')) {
         $message->setVideo($this->parseVideo($messageObject->video));
     }
     if (property_exists($messageObject, 'voice')) {
         $message->setVoice($this->parseVoice($messageObject->voice));
     }
     if (property_exists($messageObject, 'caption')) {
         $message->setCaption($messageObject->caption);
     }
     if (property_exists($messageObject, 'contact')) {
         $message->setContact($this->parseContact($messageObject->contact));
     }
     if (property_exists($messageObject, 'location')) {
         $message->setLocation($this->parseLocation($messageObject->location));
     }
     if (property_exists($messageObject, 'new_chat_participant')) {
         $message->setNewChatParticipant($this->parseUser($messageObject->new_chat_participant));
     }
     if (property_exists($messageObject, 'left_chat_participant')) {
         $message->setLeftChatParticipant($this->parseUser($messageObject->left_chat_participant));
     }
     if (property_exists($messageObject, 'new_chat_title')) {
         $message->setNewChatTitle($messageObject->new_chat_title);
     }
     if (property_exists($messageObject, 'new_chat_photo')) {
         $message->setNewChatPhoto($this->parsePhotoSize($messageObject->new_chat_photo));
     }
     // TODO: not sure about implementation of TRUE type
     if (property_exists($messageObject, 'delete_chat_photo')) {
         $message->setDeleteChatPhoto($messageObject->delete_chat_photo);
     }
     if (property_exists($messageObject, 'group_chat_created')) {
         $message->setGroupChatCreated($messageObject->group_chat_created);
     }
     return $message;
 }
Exemplo n.º 10
0
 public function loadAllSent()
 {
     $conn = $this->connection;
     $arrayWithMessages = [];
     $sqlQuery = "SELECT id, text, receiver_id, created_at FROM messages WHERE sender_id = {$this->id} ORDER BY messages.created_at DESC";
     $result = $conn->query($sqlQuery);
     if ($result->num_rows > 0) {
         while (list($id, $text, $receiverId, $createdAt) = $result->fetch_array(MYSQLI_NUM)) {
             $message = new Message($conn);
             $message->setId($id);
             $message->setText($text);
             $message->setSenderId($this->id);
             $message->setReceiverId($receiverId);
             $message->setCreatedAt($createdAt);
             $arrayWithMessages[] = $message;
         }
         return $arrayWithMessages;
     }
     return false;
 }
Exemplo n.º 11
0
include_once "configRoot.php";
require_once ROOT_NAME . "/includes/authToken.php";
require_once ROOT_NAME . "/includes/checkProfile.php";
require_once ROOT_NAME . "/classes/Database.php";
require_once ROOT_NAME . "/classes/Message.php";
$receiverId = $_GET["receiver_id"];
$receiverNick = $_GET["receiver_nick"];
$senderId = $id;
// id from a cookie
if (isset($_POST["message"])) {
    $text = $_POST["message"];
    $db = Database::getInstance();
    $conn = $db->getConnection();
    $message = new Message($conn);
    $message->setText($text);
    $message->setReceiverId($receiverId);
    $message->setSenderId($senderId);
    $result = $message->addToDatabase();
    if ($result) {
        echo "<h2>Message sent!</h2>";
    } else {
        echo "<p>Error</p>";
    }
}
?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">