Back | Home
الـ Path الحالي: /home/picotech/domains/instantly.picotech.app/public_html/public/uploads/./../../app/EmailProvider
الملفات الموجودة في هذا الـ Path:
.
..
AmazonSmtp.php
ElasticApi.php
ElasticSmtp.php
MailGunApi.php
MailGunSmtp.php
SendEMail.php
SendGridApi.php
SendMailInterface.php
SendMailProcess.php
Sendmail.php
Smtp.php
SparkpostSmtp.php
مشاهدة ملف: Smtp.php
<?php
namespace App\EmailProvider;
use App\Models\MessageLog;
use App\Models\SendingServer;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use \App\Events\SendEMail;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mime\Crypto\DkimSigner;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Address;
class Smtp implements SendMailInterface
{
private $errors;
private $message_id;
public function __construct($messageId)
{
$this->message_id=$messageId; //email_queues id
$this->errors=[];
}
public function setFrom($from, $fromName)
{
$this->from = new Address($from, $fromName);
return $this;
}
public function setReplyTo($reply_to)
{
$this->reply_to = $reply_to;
return $this;
}
public function setTo($to)
{
$this->to = $to;
return $this;
}
public function setSubject($subject)
{
$this->subject = $subject;
return $this;
}
public function setBody($body)
{
$this->body = $body;
return $this;
}
public function setFiles($files){
$files = json_decode($files);
$files_arr = [];
if ($files) {
foreach ($files as $file) {
$files_arr[] = $file;
}
}
$this->files = $files_arr;
return $this;
}
public function setConfig($config){
$this->config=$config;
return $this;
}
public function process()
{
try{
$server = $this->config;
if(isset($server->from) && $server->from == 'smtp' && isset($server->value)) {
$config_value = json_decode($server->value);
/* smtp://username:password@host:port */
$transport = Transport::fromDsn("smtp://".urlencode($config_value->username).":".urlencode($config_value->password)."@".urlencode($config_value->hostname).":$config_value->port");
$mailer = new Mailer($transport);
$email = (new Email())
->from($this->from)
->to($this->to)
->replyTo($this->reply_to)
->priority(Email::PRIORITY_NORMAL)
->subject($this->subject)
// ->text('This is an important message!')
->html($this->body);
if(isset($config_value->dkim_private_key) && isset($config_value->dkim_domain) && isset($config_value->dkim_selector)){
$signer = new DkimSigner($config_value->dkim_private_key, $config_value->dkim_domain, $config_value->dkim_selector);
$email = $signer->sign($email);
}
$mailer->send($email);
}
}catch (\Exception $ex){
if(config('app.debug')){
Log::info($ex->getMessage());
}
$this->errors[]=[
'id'=>$this->message_id,
'message'=>$ex->getMessage()
];
}
return $this;
}
public function errors(){
return $this->errors;
}
}