mirror of
https://github.com/shadoll/sLetter.git
synced 2025-12-21 03:25:04 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5109fbf54 | ||
|
|
ca599f35bc | ||
|
|
d42ecbf891 | ||
|
|
de70577a72 | ||
|
|
247841160c | ||
|
|
5eec9aa10e | ||
|
|
dc92bc18d4 | ||
|
|
563524fca4 | ||
|
|
6f8fb693a1 | ||
|
|
7eee0fb80e | ||
|
|
002fbbb4fc | ||
|
|
6cb972fe73 | ||
|
|
9d302c9540 | ||
|
|
91d1e47a05 | ||
|
|
6656909deb |
86
README.md
86
README.md
@@ -1 +1,87 @@
|
|||||||
# sLetter
|
# sLetter
|
||||||
|
|
||||||
|
e-mail send library
|
||||||
|
|
||||||
|
## install
|
||||||
|
|
||||||
|
`composer require shadoll/sletter`
|
||||||
|
|
||||||
|
https://packagist.org/packages/shadoll/sletter
|
||||||
|
|
||||||
|
## usage
|
||||||
|
|
||||||
|
```
|
||||||
|
require __DIR__.'/../vendor/autoload.php';
|
||||||
|
|
||||||
|
$letter = (new shadoll\sLetter);
|
||||||
|
```
|
||||||
|
|
||||||
|
set mail variables:
|
||||||
|
|
||||||
|
```
|
||||||
|
$letter->set([
|
||||||
|
'language' => 'ua', // set language (en|ua|ru), default 'en'
|
||||||
|
'logoUri' => "https://site.com/logo.png", // link to logo that showing in letter
|
||||||
|
'fromMail' => "site@site.com", // sender email
|
||||||
|
'fromName' => "SiteLetter", // sender name
|
||||||
|
'toMail' => "info@site.com", // resipient email
|
||||||
|
'senderDetect' => true, // detect sender location by IP, default 'true'
|
||||||
|
'senderIP' => $_SERVER['REMOTE_ADDR'],
|
||||||
|
'sender' => 'mailgun', // sender - support mail or mailgun-service
|
||||||
|
'mailgun_apikey' => 'key',
|
||||||
|
'mailgun_domain' => 'mg.site.com',
|
||||||
|
]);
|
||||||
|
```
|
||||||
|
|
||||||
|
adding fields titles:
|
||||||
|
|
||||||
|
```
|
||||||
|
$letter->setLang([
|
||||||
|
'order' => 'Замовлення',
|
||||||
|
'message' => 'Повідомлення',
|
||||||
|
'comment' => 'Повідомлення',
|
||||||
|
'date' => 'Дата',
|
||||||
|
'time' => 'Час',
|
||||||
|
'type' => 'Тип',
|
||||||
|
'doors' => 'Кількість дверцят',
|
||||||
|
'width' => 'Ширина',
|
||||||
|
'depth' => 'Глибина',
|
||||||
|
]);
|
||||||
|
```
|
||||||
|
|
||||||
|
set fields from form:
|
||||||
|
|
||||||
|
```
|
||||||
|
$letter->setData([
|
||||||
|
'name' => !empty($_REQUEST['name'])?($_REQUEST['name']):'',
|
||||||
|
'phone' => !empty($_REQUEST['phone'])?($_REQUEST['phone']):'',
|
||||||
|
'email' => !empty($_REQUEST['email'])?($_REQUEST['email']):'',
|
||||||
|
'message' => !empty($_REQUEST['message'])?($_REQUEST['message']):'',
|
||||||
|
]);
|
||||||
|
```
|
||||||
|
|
||||||
|
fields list to validate before send (not working now):
|
||||||
|
|
||||||
|
```
|
||||||
|
$letter
|
||||||
|
->validate([
|
||||||
|
'name',
|
||||||
|
'phone',
|
||||||
|
'email',
|
||||||
|
])
|
||||||
|
```
|
||||||
|
|
||||||
|
sending email
|
||||||
|
|
||||||
|
```
|
||||||
|
$letter
|
||||||
|
->detect()
|
||||||
|
->send()
|
||||||
|
->state();
|
||||||
|
```
|
||||||
|
|
||||||
|
detect - get sender info from his IP
|
||||||
|
|
||||||
|
send - if no error send email
|
||||||
|
|
||||||
|
state - action result (not fully working now)
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
{
|
{
|
||||||
"name": "shadoll/sletter",
|
"name": "shadoll/sletter",
|
||||||
"description": "shadoll sLetter - e-mail send library",
|
"description": "shadoll sLetter - e-mail send library",
|
||||||
"version": "18.2.13",
|
"prefer-stable": true,
|
||||||
"prefer-stable": true,
|
"require": {
|
||||||
"require": {
|
"php": "^7.0",
|
||||||
"php": "^7.0",
|
"mailgun/mailgun-php": "^2.4",
|
||||||
"mailgun/mailgun-php": "^2.4"
|
"wixel/gump": "dev-master"
|
||||||
},
|
},
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "sHa",
|
"name": "sHa",
|
||||||
"email": "sha@shadoll.com"
|
"email": "sha@shadoll.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"shadoll\\": "/lib"
|
"shadoll\\": "/lib"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev"
|
"minimum-stability": "dev"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* @author sHa <sha@shadoll.com>
|
* @author sHa <sha@shadoll.com>
|
||||||
* @package sLetter
|
* @package sLetter
|
||||||
* @version 18.2.12
|
* @version 18.2.13
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author sHa <sha@shadoll.com>
|
* @author sHa <sha@shadoll.com>
|
||||||
* @package shadoll/sLetter
|
* @package sLetter
|
||||||
* @version 18.2.12
|
* @version 18.2.13-13
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -16,12 +16,13 @@ class sLetter{
|
|||||||
public $error = false;
|
public $error = false;
|
||||||
public $status = "";
|
public $status = "";
|
||||||
|
|
||||||
|
private $senderDetect = true;
|
||||||
private $sender = "mail";
|
private $sender = "mail";
|
||||||
private $header = "";
|
private $header = "";
|
||||||
private $message = "";
|
private $message = "";
|
||||||
private $subject = "";
|
private $subject = "";
|
||||||
|
|
||||||
private $language = "ua";
|
private $language = "en";
|
||||||
private $lang = [];
|
private $lang = [];
|
||||||
|
|
||||||
private $fromMail = "";
|
private $fromMail = "";
|
||||||
@@ -33,10 +34,18 @@ class sLetter{
|
|||||||
private $logoUri = "";
|
private $logoUri = "";
|
||||||
|
|
||||||
function __construct(){
|
function __construct(){
|
||||||
$this->setLang(require_once(__DIR__."/lng/".$this->language.".php"));
|
$this->loadLanguage();
|
||||||
|
if($this->senderDetect)
|
||||||
|
$this->detect();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setData($data,$return=false){
|
function loadLanguage($return=false){
|
||||||
|
$this->setLang(require_once(__DIR__."/lng/".$this->language.".php"));
|
||||||
|
|
||||||
|
return $return?$this->lang:$this;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setData($data,$raw=false,$return=false){
|
||||||
if(empty($data) || !is_array($data))
|
if(empty($data) || !is_array($data))
|
||||||
return $return?$this->fields:$this;
|
return $return?$this->fields:$this;
|
||||||
|
|
||||||
@@ -45,7 +54,10 @@ class sLetter{
|
|||||||
|
|
||||||
foreach($data as $key=>$val)
|
foreach($data as $key=>$val)
|
||||||
if(!empty($val))
|
if(!empty($val))
|
||||||
$this->fields[$key] = is_string($val)?trim(stripslashes($val)):$val;
|
if(!$raw)
|
||||||
|
$this->fields[$key] = is_string($val)?trim(stripslashes(strip_tags($val))):$val;
|
||||||
|
else
|
||||||
|
$this->fields[$key] = is_string($val)?trim($val):$val;
|
||||||
|
|
||||||
return $return?$this->fields:$this;
|
return $return?$this->fields:$this;
|
||||||
}
|
}
|
||||||
@@ -67,8 +79,11 @@ class sLetter{
|
|||||||
function set($data){
|
function set($data){
|
||||||
if(!empty($data) && is_array($data))
|
if(!empty($data) && is_array($data))
|
||||||
foreach($data as $key=>$val)
|
foreach($data as $key=>$val)
|
||||||
if(!empty($key) && !empty($val))
|
if(!empty($key) && !empty($val)){
|
||||||
$this->{$key} = is_string($val)?trim(stripslashes($val)):$val;
|
$this->{$key} = is_string($val)?trim(stripslashes($val)):$val;
|
||||||
|
if($key=='language')
|
||||||
|
$this->loadLanguage();
|
||||||
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +103,9 @@ class sLetter{
|
|||||||
}
|
}
|
||||||
|
|
||||||
function message($return=false){
|
function message($return=false){
|
||||||
|
if(empty($this->lang))
|
||||||
|
$this->loadLanguage();
|
||||||
|
|
||||||
$this->message .= "<html><body style='font-family:Arial,sans-serif;'>";
|
$this->message .= "<html><body style='font-family:Arial,sans-serif;'>";
|
||||||
|
|
||||||
if(!empty($this->logoUri))
|
if(!empty($this->logoUri))
|
||||||
@@ -107,11 +125,12 @@ class sLetter{
|
|||||||
}
|
}
|
||||||
|
|
||||||
function detect($return=false){
|
function detect($return=false){
|
||||||
|
if(empty($this->senderIP))
|
||||||
|
$this->senderIP = $_SERVER['REMOTE_ADDR'];
|
||||||
|
|
||||||
if(!empty($this->senderIP)){
|
if(!empty($this->senderIP)){
|
||||||
$query = @unserialize(file_get_contents('http://ip-api.com/php/'.$this->senderIP));
|
$query = @unserialize(file_get_contents('http://ip-api.com/php/'.$this->senderIP));
|
||||||
if($query && $query['status'] == 'success'){
|
if($query && $query['status'] == 'success'){
|
||||||
|
|
||||||
|
|
||||||
$this->setData([
|
$this->setData([
|
||||||
'senderIP' => $this->senderIP,
|
'senderIP' => $this->senderIP,
|
||||||
'flag' => "<img style='height:14px; width:auto' src='http://www.geognos.com/api/en/countries/flag/".$query['countryCode'].".png'>",
|
'flag' => "<img style='height:14px; width:auto' src='http://www.geognos.com/api/en/countries/flag/".$query['countryCode'].".png'>",
|
||||||
@@ -119,19 +138,18 @@ class sLetter{
|
|||||||
'region' => $query['regionName'],
|
'region' => $query['regionName'],
|
||||||
'city' => $query['city'],
|
'city' => $query['city'],
|
||||||
'provider' => $query['isp'],
|
'provider' => $query['isp'],
|
||||||
]);
|
],true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $return?$this->fields:$this;
|
return $return?$this->fields:$this;
|
||||||
}
|
}
|
||||||
|
|
||||||
function validate($data,$return=false){
|
function validate($data,$return=false){
|
||||||
if(!empty($data) && is_array($data))
|
$is_valid = \GUMP::is_valid($this->fields, $data);
|
||||||
foreach($data as $val)
|
if($is_valid !== true){
|
||||||
if(empty($val)){
|
$this->error = true;
|
||||||
$this->error = true;
|
$this->status = $is_valid;
|
||||||
$this->status = "Empty value";
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $return?$this->error:$this;
|
return $return?$this->error:$this;
|
||||||
}
|
}
|
||||||
|
|||||||
8
sLetter.code-workspace
Normal file
8
sLetter.code-workspace
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user