Last active
May 21, 2022 19:35
-
-
Save aduartem/cc5f50a43bb0499f2a05bdf05e60146d to your computer and use it in GitHub Desktop.
Consumir Amazon SES en Lumen a utilizando PHPMailer
This file contains hidden or 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
| <?php | |
| namespace App; | |
| use Illuminate\Database\Eloquent\Model; | |
| use Log; | |
| class Amazon_ses extends Model | |
| { | |
| private $_amazon_ses; | |
| public function __construct() | |
| { | |
| parent::__construct(); | |
| $this->_amazon_ses = array( | |
| 'protocol' => 'smtp', | |
| 'smtp_host' => 'ssl://email-smtp.us-east-1.amazonaws.com', | |
| 'smtp_user' => 'USER', // Reemplazar por el user | |
| 'smtp_pass' => 'PASS', // Reemplazar por el password | |
| 'smtp_port' => 465, | |
| 'mailtype' => 'html' | |
| ); | |
| } | |
| public function send($subject, $message, $to) | |
| { | |
| $mail = new \PHPMailer(true); | |
| try | |
| { | |
| $mail->isSMTP(); | |
| $mail->CharSet = "utf-8"; | |
| $mail->SMTPAuth = true; | |
| $mail->SMTPSecure = "tls"; // or ssl | |
| $mail->Host = $this->_amazon_ses['smtp_host']; | |
| $mail->Port = $this->_amazon_ses['smtp_port']; | |
| $mail->Username = $this->_amazon_ses['smtp_user']; | |
| $mail->Password = $this->_amazon_ses['smtp_pass']; | |
| $mail->setFrom('contacto@dentalink.cl', 'Comprobante Pago'); | |
| $mail->Subject = $subject; | |
| $mail->MsgHTML($message); | |
| $mail->addAddress($to['email'], $to['name']); | |
| if( ! $mail->send()) | |
| { | |
| Log::error(__METHOD__ . ' => ' . $mail->ErrorInfo); | |
| return FALSE; | |
| } | |
| Log::info(__METHOD__ . ' => Success'); | |
| return TRUE; | |
| } | |
| catch (phpmailerException $e) | |
| { | |
| dd($e); | |
| return FALSE; | |
| } | |
| catch (Exception $e) | |
| { | |
| dd($e); | |
| return FALSE; | |
| } | |
| } | |
| } |
This file contains hidden or 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
| { | |
| "name": "laravel/lumen", | |
| "description": "The Laravel Lumen Framework.", | |
| "keywords": ["framework", "laravel", "lumen"], | |
| "license": "MIT", | |
| "type": "project", | |
| "require": { | |
| "php": ">=5.5.9", | |
| "laravel/lumen-framework": "5.2.*", | |
| "vlucas/phpdotenv": "~2.2", | |
| "aws/aws-sdk-php": "3.*", | |
| "phpmailer/phpmailer": "~5.2" | |
| }, | |
| "require-dev": { | |
| "fzaninotto/faker": "~1.4", | |
| "phpunit/phpunit": "~4.0" | |
| }, | |
| "autoload": { | |
| "psr-4": { | |
| "App\\": "app/" | |
| } | |
| }, | |
| "autoload-dev": { | |
| "classmap": [ | |
| "tests/", | |
| "database/" | |
| ] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment