sendEmail() публичный Метод

Send an email.
public sendEmail ( string $from, string $to, string $subject, string $htmlBody = NULL, string $textBody = NULL, string $tag = NULL, boolean $trackOpens = true, string $replyTo = NULL, string $cc = NULL, string $bcc = NULL, array $headers = NULL, array $attachments = NULL, string $trackLinks = NULL ) : Postmark\Models\DynamicResponseModel
$from string The sender of the email. (Your account must have an associated Sender Signature for the address used.)
$to string The recipient of the email.
$subject string The subject of the email.
$htmlBody string The HTML content of the message, optional if Text Body is specified.
$textBody string The text content of the message, optional if HTML Body is specified.
$tag string A tag associated with this message, useful for classifying sent messages.
$trackOpens boolean True if you want Postmark to track opens of HTML emails.
$replyTo string Reply to email address.
$cc string Carbon Copy recipients, comma-separated
$bcc string Blind Carbon Copy recipients, comma-separated.
$headers array Headers to be included with the sent email message.
$attachments array An array of PostmarkAttachment objects.
$trackLinks string Can be any of "None", "HtmlAndText", "HtmlOnly", "TextOnly" to enable link tracking.
Результат Postmark\Models\DynamicResponseModel
 function testClientCanSendMessageWithFileSystemAttachment()
 {
     $tk = parent::$testKeys;
     $client = new PostmarkClient($tk->WRITE_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT);
     $currentTime = date("c");
     $attachment = PostmarkAttachment::fromFile(dirname(__FILE__) . '/postmark-logo.png', "hello.png", "image/png");
     $response = $client->sendEmail($tk->WRITE_TEST_SENDER_EMAIL_ADDRESS, $tk->WRITE_TEST_EMAIL_RECIPIENT_ADDRESS, "Hello from the PHP Postmark Client Tests! ({$currentTime})", '<b>Hi there! From <img src="cid:hello.png"/></b>', 'This is a text body for a test email.', NULL, true, NULL, NULL, NULL, array("X-Test-Header" => "Header.", 'X-Test-Header-2' => 'Test Header 2'), array($attachment));
     $this->assertNotEmpty($response, 'The client could not send a message with an attachment.');
 }
 /**
  * Send Footer contact us email
  *
  * @return boolean response
  */
 public function sendFooterContactUsEmail()
 {
     $postMarkKey = getenv("POSTMARK_API_KEY");
     if (empty($postMarkKey)) {
         return false;
     }
     $client = new PostmarkClient($postMarkKey);
     $input = Input::all();
     if (!empty($input['email']) && !empty($input['name']) && !empty($input['message'])) {
         try {
             $dateText = date('F j, Y, g:i a', strtotime('+5 hours 30 minutes')) . " IST";
             $sendResult = $client->sendEmail("<from-email>", "<to-email>", "Contact Us email sent on " . $dateText, "Name: " . $input['name'] . ", From: " . $input['email'] . ", Message: " . $input['message']);
             //Send an email thanking the visitor
             $sendResult = $client->sendEmail("<from-email>", $input['email'], "Thanks for contacting Income Tax Query!", "Thank You!");
         } catch (Exception $e) {
             echo 'Caught exception: ', $e->getMessage(), "\n";
             return false;
         }
     } else {
         return false;
     }
     return 'SEND';
 }
 public function sendPostmarked($to, $from, $subject, $htmlContent, $plainContent, $attachedFiles, $customheaders, $signature = null)
 {
     if (empty($signature)) {
         $signature = PostmarkSignature::get()->filter('Email', $from)->first();
     }
     if (!$signature) {
         $signature = PostmarkSignature::get()->filter('IsDefault', 1)->first();
     }
     $client = new PostmarkClient(SiteConfig::current_site_config()->PostmarkToken);
     $customerIDs = PostmarkHelper::client_list()->filter('Email', explode(',', $to))->column('ID');
     $message = null;
     if (is_array($customerIDs) && !empty($customerIDs) && self::$record_emails) {
         $message = new PostmarkMessage(array('Subject' => $subject, 'Message' => $htmlContent, 'PlainMessage' => $plainContent, 'ToID' => implode(',', $customerIDs), 'FromID' => $signature ? $signature->ID : $signature, 'InReplyToID' => self::$reply_to_message));
         $message->write();
     }
     $cc = null;
     if (isset($customheaders['CC'])) {
         $cc = $customheaders['CC'];
         unset($customheaders['CC']);
     }
     if (isset($customheaders['cc'])) {
         $cc = $customheaders['cc'];
         unset($customheaders['cc']);
     }
     $bcc = null;
     if (isset($customheaders['Bcc'])) {
         $bcc = $customheaders['Bcc'];
         unset($customheaders['Bcc']);
     }
     if (isset($customheaders['BCC'])) {
         $bcc = $customheaders['bcc'];
         unset($customheaders['BCC']);
     }
     if (isset($customheaders['bcc'])) {
         $bcc = $customheaders['bcc'];
         unset($customheaders['bcc']);
     }
     $attachments = null;
     if ($attachedFiles && is_array($attachedFiles)) {
         $attachments = array();
         foreach ($attachedFiles as $attachment) {
             $attachments[] = PostmarkAttachment::fromRawData($attachment['contents'], $attachment['filename'], $attachment['mimetype']);
             if (is_array($customerIDs) && !empty($customerIDs) && self::$record_emails) {
                 $postmarkAttachment = new Attachment(array('Content' => base64_encode($attachment['contents']), 'FileName' => $attachment['filename'], 'ContentType' => $attachment['mimetype'], 'PostmarkMessageID' => $message->ID, 'Length' => strlen($attachment['contents'])));
                 $postmarkAttachment->write();
             }
         }
     }
     $arrangedHeaders = null;
     if ($customheaders && is_array($customheaders) && count($customheaders)) {
         $arrangedHeaders = array();
         foreach ($customheaders as $key => $val) {
             $arrangedHeaders[$key] = $val;
         }
     }
     $sendResult = $client->sendEmail($signature ? $signature->Email : $from, $to, $subject, $htmlContent, $plainContent, null, true, $message ? $message->replyToEmailAddress() : $from, $cc, $bcc, $arrangedHeaders, $attachments);
     if (is_array($customerIDs) && !empty($customerIDs) && self::$record_emails && $sendResult->__get('message') == 'OK') {
         $message->MessageID = $sendResult->__get('messageid');
         $message->write();
     }
     return $sendResult->__get('message') == 'OK';
 }
    $article = $_POST["article_id"];
    // update mySQL
    CS50::query("UPDATE portfolio SET status = 3 WHERE id = ?", $article);
    // set submission destination and subject
    $email_to = "*****@*****.**";
    $email_subject = "Crimson Article Submission";
    // Actual article text variable
    $articles = $_POST['articles'];
    // Start of email message
    $email_message = "Form details below.\n\n";
    // Get title of article
    $pieces = CS50::query("SELECT title FROM portfolio WHERE id = ?", $article);
    $piece = $pieces[0]["title"];
    // Get name of comper
    $compers = CS50::query("SELECT name, email FROM users WHERE userid = ?", $_SESSION["id"]);
    $name = $compers[0]["name"];
    $email = $compers[0]["email"];
    // Craft e-mail message body
    $email_message .= "Comper: " . $name . "\r\n";
    $email_message .= "Article Title: " . $piece . "\r\n";
    $email_message .= "Comments: " . $articles . "\r\n";
    $client = new PostmarkClient("211bda55-ecef-447c-ba35-7b2ca54e802f");
    // Send email
    $sendResult = $client->sendEmail("*****@*****.**", "*****@*****.**", "Comper Article Submissions", "{$email_message}");
    // Redirect
    redirect("/");
} else {
    if ($_SERVER["REQUEST_METHOD"] == "GET") {
        redirect("/");
    }
}
Пример #5
0
 public function send($recipient, $subject, $message)
 {
     $client = new Postmark(self::KEY);
     $sendResult = $client->sendEmail(self::SENDER, $recipient, $subject, $message);
 }
 /**
  * Send email through Postmark's REST API
  *
  * @return bool (true = sent successfully)
  */
 private function sendPostmarkEmail($to, $from, $subject, $htmlContent = NULL, $attachedFiles = NULL, $customHeaders = NULL, $plainContent = NULL)
 {
     $apiKey = $this->config()->get('api_key');
     $senderSignatures = $this->config()->get('sender_signatures');
     $cc = NULL;
     $bcc = NULL;
     $replyTo = NULL;
     if (!$apiKey) {
         user_error('A Postmark App API key is required to send email', E_USER_ERROR);
     }
     if (!($htmlContent || $plainContent)) {
         user_error("Can't send email with no content", E_USER_ERROR);
     }
     if (empty($senderSignatures)) {
         user_error('At least one Postmark App sender signature is required to send email', E_USER_ERROR);
     }
     // Parse out problematic custom headers
     if (is_array($customHeaders)) {
         if (array_key_exists('Cc', $customHeaders)) {
             $cc = $customHeaders['Cc'];
             unset($customHeaders['Cc']);
         }
         if (array_key_exists('Bcc', $customHeaders)) {
             $bcc = $customHeaders['Bcc'];
             unset($customHeaders['Bcc']);
         }
         if (array_key_exists('Reply-To', $customHeaders)) {
             $replyTo = $customHeaders['Reply-To'];
             unset($customHeaders['Reply-To']);
         }
         if (empty($customHeaders)) {
             $customHeaders = NULL;
         }
     } else {
         $customHeaders = NULL;
     }
     // Ensure from address is valid
     if (!in_array($from, $senderSignatures)) {
         // Fallback to first valid signature
         if (!$replyTo) {
             $replyTo = $from;
         }
         $from = $senderSignatures[0];
     }
     // Set up attachments
     $attachments = array();
     if ($attachedFiles && is_array($attachedFiles)) {
         foreach ($attachedFiles as $f) {
             $attachments[] = PostmarkAttachment::fromRawData($f['contents'], $f['filename'], $f['mimetype']);
         }
     }
     // Send the email
     try {
         $client = new PostmarkClient($apiKey);
         $sendResult = $client->sendEmail($from, $to, $subject, $htmlContent, $plainContent, $tag = NULL, $trackOpens = true, $replyTo, $cc, $bcc, $customHeaders, $attachments);
         return true;
     } catch (PostmarkException $ex) {
         // If client is able to communicate with the API in a timely fashion,
         // but the message data is invalid, or there's a server error,
         // a PostmarkException can be thrown.
         user_error("Postmark Exception: {$ex->message} (Error code: {$ex->postmarkApiErrorCode})", E_USER_WARNING);
         return false;
     } catch (Exception $generalException) {
         // A general exception is thown if the API
         // was unreachable or times out.
         user_error('Postmark API was unreachable or timed out', E_USER_WARNING);
         return false;
     }
 }
Пример #7
0
            }
        }
    }
} else {
}
include 'attachment.php';
require_once './vendor/autoload.php';
use Postmark\PostmarkClient;
use Postmark\Models\PostmarkException;
use Postmark\Models\PostmarkAttachment;
try {
    // Example request
    $client = new PostmarkClient("f5662a2d-8885-4cd1-b0b2-65b084216b3a");
    //$_FILES[file][name][type][size]
    $attachment = PostmarkAttachment::fromFile($target_dir . basename($_FILES["file"]["name"]), basename($_FILES["file"]["name"]), "text/plain");
    $sendResult = $client->sendEmail("*****@*****.**", $_POST['tosend'], "You Have a Request (No Reply)", "* You have a job application request from:" . "<br><br><br>" . "Name: " . $_POST['aname'] . "<br><br>" . "Age: " . $_POST['age'] . "<br><br>" . "Have Work Experience: " . $_POST['experience'] . "<br><br>" . "Experience About Previous Jobs: " . $_POST['area'] . "<br><br>" . "Contact: " . $_POST['contact'] . "<br><br>" . "Email: " . $_POST['email'] . "<br><br>" . "(Attachments is provided within the email)" . "<br><br>", "Attachement body", NULL, true, NULL, NULL, NULL, NULL, [$attachment]);
} catch (PostmarkException $ex) {
    // If client is able to communicate with the API in a timely fashion,
    // but the message data is invalid, or there's a server error,
    // a PostmarkException can be thrown.
    echo $ex->httpStatusCode;
    echo $ex->message;
    echo $ex->postmarkApiErrorCode;
} catch (Exception $generalException) {
    // A general exception is thown if the API
    // was unreachable or times out.
}
if ($sendResult) {
    include 'addapply.php';
    header("Location: sent.php");
} else {