phpmailer

This commit is contained in:
2023-02-08 00:59:52 +01:00
parent 1644fede7f
commit 6a7569147e
5 changed files with 69 additions and 32 deletions

5
composer.json Normal file
View File

@ -0,0 +1,5 @@
{
"require":{
"phpmailer/phpmailer": "^6.7.1"
}
}

View File

@ -1,5 +1,26 @@
<?php <?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require '../../../vendor/autoload.php';
class CNetcupMailer extends PHPMailer
{
public function __construct($debug = false)
{
parent::__construct($debug);
$this->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$this->isSMTP(); //Send using SMTP
$this->Host = 'mxe8bd.netcup.net'; //Set the SMTP server to send through
$this->SMTPAuth = true; //Enable SMTP authentication
$this->Username = 'dog@hope-fly.de'; //SMTP username
$this->Password = 'DgQduKV6uBWXQcCqmAjL'; //SMTP password
$this->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$this->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
}
}
class CMsg class CMsg
{ {
var $success; var $success;

View File

@ -62,14 +62,24 @@ if (!filter_var($toEmail, FILTER_VALIDATE_EMAIL))
return; return;
} }
$subject = 'Dog Found ' . $name .' '. $qr_id; $subject = 'Tier gefunden: ' . $name .' ID: '. $qr_id;
// $headers =
// array(
// 'From' => $fromEmail,
// 'Cc' => $fromEmail,
// 'Bcc' => 'dog@hope-fly.de'
// );
$headers = 'From: ' . $fromEmail . "\r\n";
$headers .= 'Cc: ' . $fromEmail . "\r\n";
$headers .= 'Bcc: ' . 'dog@hope-fly.de' . "\r\n\r\n";
//var_dump($headers);
$headers[] = 'From: '. $fromEmail;
$headers[] = 'Cc: '. $fromEmail;
$headers[] = 'Bcc: dog@hope-fly.de';
try try
{ {
$ret = mail($toEmail,$subject,$msg,implode("\r\n", $headers)); $ret = mail($toEmail, $subject, $msg, $headers);
if($ret) if($ret)
{ {
$result = new CMsg(1, 200, "Email send successfully."); $result = new CMsg(1, 200, "Email send successfully.");
@ -99,7 +109,10 @@ function storeEmail()
$sql = "INSERT INTO contact_emails (dogs_id, from_email, msg) VALUES (?,?,?)"; $sql = "INSERT INTO contact_emails (dogs_id, from_email, msg) VALUES (?,?,?)";
$conn->prepare($sql)->execute([$dogRes->data['id'], $fromEmail, $msg]); // throw PDO::exception when failed $conn->prepare($sql)->execute([$dogRes->data['id'], $fromEmail, $msg]); // throw PDO::exception when failed
} }
else
{
throw new Exception("qr_id: " . $qr_id . " :: " . $dogRes->message);
}
return $dogRes; return $dogRes;
} }
?> ?>

View File

@ -1,36 +1,33 @@
<?php <?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(); //Load Composer's autoloader
require './classes/lib.php';
require __DIR__.'/classes/Database.php'; //Create an instance; passing `true` enables exceptions
require __DIR__.'/classes/lib.php'; $mail = new CNetcupMailer(true);
$to_email = 'p.para@gmx.de'; try {
$subject = 'Testing PHP Mail'; //Server settings
$message = 'Bcc This mail is sent using the PHP mail function';
$headers[] = 'From: p.hoppe@gmx.de'; //Recipients
$headers[] = 'Cc: p.hoppe@gmx.de'; $mail->setFrom('p.para@gmx.de', 'Mailer');
$headers[] = 'Bcc: dog@hope-fly.de'; $mail->addAddress('p.hoppe@gmx.de', 'Joe User'); //Add a recipient
try $mail->addReplyTo('p.para@gmx.de', 'Information');
{ $mail->addCC('p.para@gmx.de');
$ret = mail($to_email,$subject,$message,implode("\r\n", $headers)); $mail->addBCC('dog@hope-fly.de');
if($ret)
{ //Attachments
echo 'mail ok\n';
} //Content
else $mail->Subject = 'jo subject jo XXXXX';
{ $mail->Body = 'XXXX This is the txt message bodyThis is the txt message body This is the txt message bodyThis is the txt message body';
echo 'mail error\n';
} $mail->send();
echo 'Message has been sent';
} }
catch (Exception $e) catch (Exception $e)
{ {
echo 'Caught exception: ', $e->getMessage(), "\n"; echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
} }
?> ?>

View File

@ -67,6 +67,7 @@ export default function DogContactForm(
if(data.success) if(data.success)
{ {
toast.success('Eine Kopie wurde auch an ' + toEmail + ' geschickt!');
toast.success('Nachricht gesendet!'); toast.success('Nachricht gesendet!');
} }
else if(!data.success && data.message) else if(!data.success && data.message)