Created
October 4, 2016 13:42
-
-
Save TiagoGouvea/ef1fabcc2d08f6587aaa4fce7e6ba587 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function sendCampaignMailSes() | |
{ | |
if ($this->date_sent != null) { | |
// Log!!! | |
$this->showLog("Already sent"); | |
return; | |
} | |
if ($this->date_sending != null) { | |
$this->showLog("Already sending! - since: " . $this->date_sending); | |
return; | |
} | |
$this->date_sending = date('Y-m-d H:m:s'); | |
$this->save(); | |
$campaign = $this->campaign(); | |
$person = $this->person(); | |
$client = $campaign->getClient(); | |
$email = $person->getPrimaryEmail(); | |
if (app()->environment() == 'dev' && strpos($email, 'tiagogouvea') === false) { | |
$this->showLog("email alterado DEV!!! Era " . $email); | |
$email = "tiago@tiagogouvea.com.br"; | |
} | |
$subject = $campaign->email_subject; | |
$html = view('campaign_mail_html', ['campaignPerson' => $this, 'person' => $person, 'client' => $client, 'campaign' => $campaign]); | |
$text = Html2Text::convert($html); | |
$this->showLog("Sending - $client->mail_from - campaign: $campaign->id - person: $person->id - to: $email"); | |
$result = $client->sendEmail($email, $subject, $html, $text); | |
if ($result['success'] !== true) { | |
$this->showLog("Send error - message: " . $result['message']); | |
$this->error_sending = substr($result['message'], 0, 150); | |
// Log rollbar? | |
} else { | |
$this->showLog("Success - message id: " . $result['message_id']); | |
$this->service_message_id = $result['message_id']; | |
$this->date_sent = date('Y-m-d H:m:s'); | |
} | |
$this->save(); | |
// nps2 - dlX5ZK,r9OO{ | |
// nps@pho - 22_tgo | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment