mail php
This commit is contained in:
88
php/php-dog/foundEmail.php
Normal file
88
php/php-dog/foundEmail.php
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
header("Access-Control-Allow-Origin: *");
|
||||||
|
header("Access-Control-Allow-Headers: access");
|
||||||
|
header("Access-Control-Allow-Methods: POST");
|
||||||
|
header("Content-Type: application/json; charset=UTF-8");
|
||||||
|
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
require __DIR__.'/classes/Database.php';
|
||||||
|
require __DIR__.'/classes/lib.php';
|
||||||
|
|
||||||
|
$db_connection = new Database();
|
||||||
|
$conn = $db_connection->dbConnection();
|
||||||
|
|
||||||
|
$returnData = new CMsg(0);
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] != "POST")
|
||||||
|
{
|
||||||
|
$returnData = new CMsg(0, 404, 'Page Not Found! REQUEST_METHOD');
|
||||||
|
echo $returnData->jsonarray();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!isset($_POST['fromEmail'])
|
||||||
|
|| !isset($_POST['toEmail'])
|
||||||
|
|| !isset($_POST['qr_id'])
|
||||||
|
|| !isset($_POST['name'])
|
||||||
|
|| !isset($_POST['msg'])
|
||||||
|
|| empty(trim($_POST['fromEmail']))
|
||||||
|
|| empty(trim($_POST['toEmail']))
|
||||||
|
|| empty(trim($_POST['qr_id']))
|
||||||
|
|| empty(trim($_POST['name']))
|
||||||
|
|| empty(trim($_POST['msg']))
|
||||||
|
)
|
||||||
|
{
|
||||||
|
$fields = ['fields' => ['fromEmail', 'toEmail', 'qr_id', 'name', 'msg']];
|
||||||
|
$returnData = new CMsg(0, 422, 'Please Fill in all Required Fields!', $fields);
|
||||||
|
echo $returnData->jsonarray();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// IF THERE ARE NO EMPTY FIELDS THEN-
|
||||||
|
$fromEmail = trim($_POST['fromEmail']);
|
||||||
|
$toEmail = trim($_POST['toEmail']);
|
||||||
|
$qr_id = trim($_POST['qr_id']);
|
||||||
|
$name = trim($_POST['name']);
|
||||||
|
$msg = trim($_POST['msg']);
|
||||||
|
|
||||||
|
if (!filter_var($fromEmail, FILTER_VALIDATE_EMAIL))
|
||||||
|
{
|
||||||
|
$returnData = new CMsg(0, 422, 'Invalid Email Address!', 'fromEmail');
|
||||||
|
echo $returnData->jsonarray();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!filter_var($toEmail, FILTER_VALIDATE_EMAIL))
|
||||||
|
{
|
||||||
|
$returnData = new CMsg(0, 422, 'Invalid Email Address!', 'toEmail');
|
||||||
|
echo $returnData->jsonarray();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$subject = 'Dog Found ' . $name .' '. $qr_id;
|
||||||
|
|
||||||
|
$headers[] = 'From: '. $fromEmail;
|
||||||
|
$headers[] = 'Cc: '. $fromEmail;
|
||||||
|
$headers[] = 'Bcc: dog@hope-fly.de';
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$ret = mail($toEmail,$subject,$msg,implode("\r\n", $headers));
|
||||||
|
if($ret)
|
||||||
|
{
|
||||||
|
$result = new CMsg(1, 200, "Email send successfully.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$result = new CMsg(1, 500, "Sorry, there was an error sending your email your file.");
|
||||||
|
}
|
||||||
|
echo $result->jsonarray();
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
$result = new CMsg(0, 500, $e->getMessage() );
|
||||||
|
echo $result->jsonarray();
|
||||||
|
}
|
||||||
|
?>
|
||||||
36
php/php-dog/tstEmail.php
Normal file
36
php/php-dog/tstEmail.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
header("Access-Control-Allow-Origin: *");
|
||||||
|
header("Access-Control-Allow-Headers: access");
|
||||||
|
header("Access-Control-Allow-Methods: POST");
|
||||||
|
header("Content-Type: application/json; charset=UTF-8");
|
||||||
|
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
require __DIR__.'/classes/Database.php';
|
||||||
|
require __DIR__.'/classes/lib.php';
|
||||||
|
|
||||||
|
|
||||||
|
$to_email = 'p.para@gmx.de';
|
||||||
|
$subject = 'Testing PHP Mail';
|
||||||
|
$message = 'Bcc This mail is sent using the PHP mail function';
|
||||||
|
$headers[] = 'From: p.hoppe@gmx.de';
|
||||||
|
$headers[] = 'Cc: p.hoppe@gmx.de';
|
||||||
|
$headers[] = 'Bcc: dog@hope-fly.de';
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$ret = mail($to_email,$subject,$message,implode("\r\n", $headers));
|
||||||
|
if($ret)
|
||||||
|
{
|
||||||
|
echo 'mail ok\n';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo 'mail error\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
echo 'Caught exception: ', $e->getMessage(), "\n";
|
||||||
|
}
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user