mirror of
https://github.com/shadoll/slavforest.git
synced 2025-10-26 23:18:40 +00:00
mail send upgrade
This commit is contained in:
7
.env
Normal file
7
.env
Normal file
@@ -0,0 +1,7 @@
|
||||
SMTP_SERVER=smtp.mailgun.org
|
||||
SMTP_USER=site@mg.slavforest.com.ua
|
||||
SMTP_PASSWORD=bec5494ae5dd629663b3150237e6f361-af6c0cec-6f6edfe8
|
||||
SMTP_RECEIVER=slavforest@gmail.com
|
||||
|
||||
SENDER_NAME='Site form slavforest.com.ua'
|
||||
SENDER_EMAIL=site@mg.slavforest.com.ua
|
||||
7
.env.example
Normal file
7
.env.example
Normal file
@@ -0,0 +1,7 @@
|
||||
SMTP_SERVER=smtp.mailgun.org
|
||||
SMTP_USER=site@mg.slavforest.com.ua
|
||||
SMTP_PASSWORD=bec5494ae5dd629663b3150237e6f361-af6c0cec-6f6edfe8
|
||||
SMTP_RECEIVER=test2@shadoll.com
|
||||
|
||||
SENDER_NAME=Site form slavforest.com.ua
|
||||
SENDER_EMAIL=site@mg.slavforest.com.ua
|
||||
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"name": "shadoll/slavforest",
|
||||
"description": "Slav forest site",
|
||||
"require": {
|
||||
"slim/slim": "^3.0",
|
||||
"mailgun/mailgun-php": "^2.6",
|
||||
"slim/php-view": "^2.2"
|
||||
"vlucas/phpdotenv": "^3.6",
|
||||
"phpmailer/phpmailer": "^6.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
<?php
|
||||
$sendfrom = "site@slavforest.com.ua";
|
||||
$sendto = "sha@shadoll.work; info@slavforest.com.ua";
|
||||
|
||||
$subject = "📨 Повідомлення з сайту slavforest.com.ua";
|
||||
|
||||
$username = !empty($_POST['name'])?trim(stripslashes($_POST['name'])):'';
|
||||
$userphone = !empty($_POST['phone'])?trim(stripslashes($_POST['phone'])):'';
|
||||
$usermail = !empty($_POST['email'])?trim(stripslashes($_POST['email'])):'';
|
||||
|
||||
$order = !empty($_POST['order'])?trim(stripslashes($_POST['order'])):'';
|
||||
$subj = !empty($_POST['subject'])?trim(stripslashes($_POST['subject'])):'';
|
||||
$message = !empty($_POST['message'])?trim(stripslashes($_POST['message'])):'';
|
||||
|
||||
$referer = !empty($_POST['referer'])?trim(stripslashes($_POST['referer'])):'';
|
||||
|
||||
$ip = $_SERVER['REMOTE_ADDR']; // the IP address to query
|
||||
$query = @unserialize(file_get_contents('http://ip-api.com/php/'.$ip));
|
||||
if($query && $query['status'] == 'success') {
|
||||
$detect = true;
|
||||
$country_code = $query['countryCode'];
|
||||
$country = $query['country'];
|
||||
$region = $query['regionName'];
|
||||
$city = $query['city'];
|
||||
$provider = $query['isp'];
|
||||
}
|
||||
else
|
||||
$detect = false;
|
||||
|
||||
$headers = "From:".strip_tags($sendfrom)."\r\n";
|
||||
if(!empty($usermail))
|
||||
$headers .= "Reply-To: ".strip_tags($usermail)."\r\n";
|
||||
else
|
||||
$headers .= "Reply-To: ".strip_tags($sendto)."\r\n";
|
||||
$headers .= "MIME-Version: 1.0\r\n";
|
||||
$headers .= "Content-Type: text/html;charset=utf-8 \r\n";
|
||||
|
||||
$msg = "<html><body style='font-family:Arial,sans-serif;'>";
|
||||
$msg .= '<img src="https://zebnits.com/images/logo_black.png" alt="logo">';
|
||||
$msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>".$subject."</h2>\r\n";
|
||||
$msg .= "<p><strong>Від кого:</strong> ".$username."</p>\r\n";
|
||||
if(!empty($userphone))
|
||||
$msg .= "<p><strong>Телефон:</strong> ".$userphone."</p>\r\n";
|
||||
if(!empty($usermail))
|
||||
$msg .= "<p><strong>Email:</strong> ".$usermail."</p>\r\n";
|
||||
$msg .= "<hr>\r\n";
|
||||
if(!empty($subj))
|
||||
$msg .= "<p><strong>Тема:</strong>\r\n".$subj."</p>\r\n";
|
||||
if(!empty($order))
|
||||
$msg .= "<p><strong>Заказ:</strong>\r\n".$order."</p>\r\n";
|
||||
if(!empty($message))
|
||||
$msg .= "<p><strong>Повідомлення:</strong>\r\n".$message."</p>\r\n";
|
||||
$msg .= "<hr>\r\n";
|
||||
$msg .= "<p><strong>Реферал:</strong> ".$referer."</p>\r\n";
|
||||
$msg .= "<p><strong>IP-адреса відправника:</strong> ".$ip."</p>\r\n";
|
||||
if($detect){
|
||||
$msg .= "<p><strong>Провайдер:</strong> ".$provider."</p>\r\n";
|
||||
$msg .= "<p><strong>Країна:</strong> ".$country." <img style='height:14px; width:auto' src='http://www.geognos.com/api/en/countries/flag/".$country_code.".png'></p>\r\n";
|
||||
$msg .= "<p><strong>Регіон:</strong> ".$region."</p>\r\n";
|
||||
$msg .= "<p><strong>Населений пункт:</strong> ".$city."</p>\r\n";
|
||||
}
|
||||
$msg .= "</body></html>";
|
||||
|
||||
if(empty($username)){
|
||||
echo json_encode([
|
||||
'message'=>'Please enter your name.',
|
||||
'callback'=>'error',
|
||||
'focus'=>'name'
|
||||
]);
|
||||
}
|
||||
elseif(empty($usermail)){
|
||||
echo json_encode([
|
||||
'message'=>'Please enter valid e-mail.',
|
||||
'callback'=>'error',
|
||||
'focus'=>'email'
|
||||
]);
|
||||
}
|
||||
else{
|
||||
$success = @mail($sendto, $subject, $msg, $headers);
|
||||
|
||||
echo json_encode([
|
||||
'html'=>'our message has been sent. We will reply soon. Thank you!',
|
||||
'target'=>".response",
|
||||
'callback'=>"message_send"
|
||||
]);
|
||||
}
|
||||
90
contactengine.php.bak
Normal file
90
contactengine.php.bak
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
$sendfrom = "site@slavforest.com.ua";
|
||||
$sendto = "sha@shadoll.work; info@slavforest.com.ua";
|
||||
|
||||
$subject = "📨 Повідомлення з сайту slavforest.com.ua";
|
||||
|
||||
$username = !empty($_POST['name'])?trim(stripslashes($_POST['name'])):'';
|
||||
$userphone = !empty($_POST['phone'])?trim(stripslashes($_POST['phone'])):'';
|
||||
$usermail = !empty($_POST['email'])?trim(stripslashes($_POST['email'])):'';
|
||||
|
||||
$order = !empty($_POST['order'])?trim(stripslashes($_POST['order'])):'';
|
||||
$subj = !empty($_POST['subject'])?trim(stripslashes($_POST['subject'])):'';
|
||||
$message = !empty($_POST['message'])?trim(stripslashes($_POST['message'])):'';
|
||||
|
||||
$referer = !empty($_POST['referer'])?trim(stripslashes($_POST['referer'])):'';
|
||||
|
||||
$ip = $_SERVER['REMOTE_ADDR']; // the IP address to query
|
||||
$query = @unserialize(file_get_contents('http://ip-api.com/php/'.$ip));
|
||||
if ($query && $query['status'] == 'success') {
|
||||
$detect = true;
|
||||
$country_code = $query['countryCode'];
|
||||
$country = $query['country'];
|
||||
$region = $query['regionName'];
|
||||
$city = $query['city'];
|
||||
$provider = $query['isp'];
|
||||
} else {
|
||||
$detect = false;
|
||||
}
|
||||
|
||||
$headers = "From:".strip_tags($sendfrom)."\r\n";
|
||||
if (!empty($usermail)) {
|
||||
$headers .= "Reply-To: ".strip_tags($usermail)."\r\n";
|
||||
} else {
|
||||
$headers .= "Reply-To: ".strip_tags($sendto)."\r\n";
|
||||
}
|
||||
$headers .= "MIME-Version: 1.0\r\n";
|
||||
$headers .= "Content-Type: text/html;charset=utf-8 \r\n";
|
||||
|
||||
$msg = "<html><body style='font-family:Arial,sans-serif;'>";
|
||||
$msg .= '<img src="https://zebnits.com/images/logo_black.png" alt="logo">';
|
||||
$msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>".$subject."</h2>\r\n";
|
||||
$msg .= "<p><strong>Від кого:</strong> ".$username."</p>\r\n";
|
||||
if (!empty($userphone)) {
|
||||
$msg .= "<p><strong>Телефон:</strong> ".$userphone."</p>\r\n";
|
||||
}
|
||||
if (!empty($usermail)) {
|
||||
$msg .= "<p><strong>Email:</strong> ".$usermail."</p>\r\n";
|
||||
}
|
||||
$msg .= "<hr>\r\n";
|
||||
if (!empty($subj)) {
|
||||
$msg .= "<p><strong>Тема:</strong>\r\n".$subj."</p>\r\n";
|
||||
}
|
||||
if (!empty($order)) {
|
||||
$msg .= "<p><strong>Заказ:</strong>\r\n".$order."</p>\r\n";
|
||||
}
|
||||
if (!empty($message)) {
|
||||
$msg .= "<p><strong>Повідомлення:</strong>\r\n".$message."</p>\r\n";
|
||||
}
|
||||
$msg .= "<hr>\r\n";
|
||||
$msg .= "<p><strong>Реферал:</strong> ".$referer."</p>\r\n";
|
||||
$msg .= "<p><strong>IP-адреса відправника:</strong> ".$ip."</p>\r\n";
|
||||
if ($detect) {
|
||||
$msg .= "<p><strong>Провайдер:</strong> ".$provider."</p>\r\n";
|
||||
$msg .= "<p><strong>Країна:</strong> ".$country." <img style='height:14px; width:auto' src='http://www.geognos.com/api/en/countries/flag/".$country_code.".png'></p>\r\n";
|
||||
$msg .= "<p><strong>Регіон:</strong> ".$region."</p>\r\n";
|
||||
$msg .= "<p><strong>Населений пункт:</strong> ".$city."</p>\r\n";
|
||||
}
|
||||
$msg .= "</body></html>";
|
||||
|
||||
if (empty($username)) {
|
||||
echo json_encode([
|
||||
'message'=>'Please enter your name.',
|
||||
'callback'=>'error',
|
||||
'focus'=>'name'
|
||||
]);
|
||||
} elseif (empty($usermail)) {
|
||||
echo json_encode([
|
||||
'message'=>'Please enter valid e-mail.',
|
||||
'callback'=>'error',
|
||||
'focus'=>'email'
|
||||
]);
|
||||
} else {
|
||||
$success = @mail($sendto, $subject, $msg, $headers);
|
||||
|
||||
echo json_encode([
|
||||
'html'=>'our message has been sent. We will reply soon. Thank you!',
|
||||
'target'=>".response",
|
||||
'callback'=>"message_send"
|
||||
]);
|
||||
}
|
||||
67
contactform.php
Normal file
67
contactform.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
require __DIR__.'/sender.php';
|
||||
|
||||
$username = !empty($_POST['name'])?trim(stripslashes($_POST['name'])):'';
|
||||
$userphone = !empty($_POST['phone'])?trim(stripslashes($_POST['phone'])):'';
|
||||
$usermail = !empty($_POST['email'])?trim(stripslashes($_POST['email'])):'';
|
||||
|
||||
$subject = !empty($_POST['subject'])?trim(stripslashes($_POST['subject'])):'';
|
||||
$message = !empty($_POST['message'])?trim(stripslashes($_POST['message'])):'';
|
||||
|
||||
$referer = !empty($_POST['referer'])?trim(stripslashes($_POST['referer'])):'';
|
||||
|
||||
if (!empty($_SERVER) && array_key_exists('REMOTE_ADDR', $_SERVER)) {
|
||||
$ip = $_SERVER['REMOTE_ADDR']; // the IP address to query
|
||||
$query = @unserialize(file_get_contents('http://ip-api.com/php/'.$ip));
|
||||
if ($query && $query['status'] == 'success') {
|
||||
$detect = true;
|
||||
$country_code = $query['countryCode'];
|
||||
$country = $query['country'];
|
||||
$region = $query['regionName'];
|
||||
$city = $query['city'];
|
||||
$provider = $query['isp'];
|
||||
} else {
|
||||
$detect = false;
|
||||
}
|
||||
} else {
|
||||
$ip = 'no IP';
|
||||
$detect = false;
|
||||
}
|
||||
|
||||
|
||||
$msg = "<html><body style='font-family:Arial,sans-serif;'>";
|
||||
$msg .= '<img style="height:60px; widht:auto" src="http://slavforest.com.ua/images/logo_w.png" alt="logo">';
|
||||
$msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>".$subject."</h2>\r\n";
|
||||
$msg .= "<p><strong>Від кого:</strong> ".$username."</p>\r\n";
|
||||
if (!empty($userphone)) {
|
||||
$msg .= "<p><strong>Телефон:</strong> ".$userphone."</p>\r\n";
|
||||
}
|
||||
if (!empty($usermail)) {
|
||||
$msg .= "<p><strong>Email:</strong> ".$usermail."</p>\r\n";
|
||||
}
|
||||
$msg .= "<hr>\r\n";
|
||||
if (!empty($subj)) {
|
||||
$msg .= "<p><strong>Тема:</strong>\r\n".$subj."</p>\r\n";
|
||||
}
|
||||
if (!empty($message)) {
|
||||
$msg .= "<p><strong>Повідомлення:</strong>\r\n".$message."</p>\r\n";
|
||||
}
|
||||
$msg .= "<hr>\r\n";
|
||||
$msg .= "<p><strong>Реферал:</strong> ".$referer."</p>\r\n";
|
||||
$msg .= "<p><strong>IP-адреса відправника:</strong> ".$ip."</p>\r\n";
|
||||
if ($detect) {
|
||||
$msg .= "<p><strong>Провайдер:</strong> ".$provider."</p>\r\n";
|
||||
$msg .= "<p><strong>Країна:</strong> ".$country." <img style='height:14px; width:auto' src='http://www.geognos.com/api/en/countries/flag/".$country_code.".png'></p>\r\n";
|
||||
$msg .= "<p><strong>Регіон:</strong> ".$region."</p>\r\n";
|
||||
$msg .= "<p><strong>Населений пункт:</strong> ".$city."</p>\r\n";
|
||||
}
|
||||
$msg .= "</body></html>";
|
||||
|
||||
$data = (object)[
|
||||
'name' => $username,
|
||||
'email' => $usermail,
|
||||
'subject' => "📨 Повідомлення з сайту slavforest.com.ua",
|
||||
'body' => $msg,
|
||||
];
|
||||
|
||||
$sender = (new sender)->send($data);
|
||||
1405
index.html
1405
index.html
File diff suppressed because it is too large
Load Diff
1353
index_en.html
1353
index_en.html
File diff suppressed because it is too large
Load Diff
@@ -273,7 +273,7 @@ $(document).ready(function() {
|
||||
}
|
||||
if (name && emaild && message) {
|
||||
$.ajax({
|
||||
url: 'contactengine.php',
|
||||
url: 'contactform.php',
|
||||
data: {
|
||||
name: name,
|
||||
email: emaild,
|
||||
|
||||
44
sender.php
Normal file
44
sender.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
require __DIR__.'/vendor/autoload.php';
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
class sender
|
||||
{
|
||||
public function send($data)
|
||||
{
|
||||
$dotenv = \Dotenv\Dotenv::create(__DIR__);
|
||||
$dotenv->load();
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
|
||||
try {
|
||||
$mail->isSMTP();
|
||||
$mail->CharSet = 'UTF-8';
|
||||
$mail->Host = getenv('SMTP_SERVER');
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = getenv('SMTP_USER');
|
||||
$mail->Password = getenv('SMTP_PASSWORD');
|
||||
$mail->SMTPSecure = 'tls';
|
||||
|
||||
$mail->From = getenv('SENDER_EMAIL');
|
||||
$mail->FromName = getenv('SENDER_NAME');
|
||||
$mail->addAddress(getenv('SMTP_RECEIVER'));
|
||||
|
||||
$mail->isHTML(true);
|
||||
$mail->Subject = $data->subject;
|
||||
$mail->Body = $data->body;
|
||||
|
||||
$mail->send();
|
||||
echo 'Message has been sent';
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user