From 6a7569147e5b9c82ab5959d5d318b5876c5dbd0b Mon Sep 17 00:00:00 2001 From: Peter Hoppe Date: Wed, 8 Feb 2023 00:59:52 +0100 Subject: [PATCH] phpmailer --- composer.json | 5 ++++ php/php-dog/classes/lib.php | 21 +++++++++++++ php/php-dog/foundEmail.php | 25 ++++++++++++---- php/php-dog/tstEmail.php | 49 +++++++++++++++---------------- src/components/DogContactForm.tsx | 1 + 5 files changed, 69 insertions(+), 32 deletions(-) create mode 100644 composer.json diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..c2fda00 --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require":{ + "phpmailer/phpmailer": "^6.7.1" + } +} \ No newline at end of file diff --git a/php/php-dog/classes/lib.php b/php/php-dog/classes/lib.php index 170d0d1..629c84c 100644 --- a/php/php-dog/classes/lib.php +++ b/php/php-dog/classes/lib.php @@ -1,5 +1,26 @@ 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 { var $success; diff --git a/php/php-dog/foundEmail.php b/php/php-dog/foundEmail.php index 7902696..5de593d 100644 --- a/php/php-dog/foundEmail.php +++ b/php/php-dog/foundEmail.php @@ -62,14 +62,24 @@ if (!filter_var($toEmail, FILTER_VALIDATE_EMAIL)) 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 { - $ret = mail($toEmail,$subject,$msg,implode("\r\n", $headers)); + $ret = mail($toEmail, $subject, $msg, $headers); if($ret) { $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 (?,?,?)"; $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; } ?> \ No newline at end of file diff --git a/php/php-dog/tstEmail.php b/php/php-dog/tstEmail.php index fda52aa..2bacccb 100644 --- a/php/php-dog/tstEmail.php +++ b/php/php-dog/tstEmail.php @@ -1,36 +1,33 @@ setFrom('p.para@gmx.de', 'Mailer'); + $mail->addAddress('p.hoppe@gmx.de', 'Joe User'); //Add a recipient + $mail->addReplyTo('p.para@gmx.de', 'Information'); + $mail->addCC('p.para@gmx.de'); + $mail->addBCC('dog@hope-fly.de'); + + //Attachments + + //Content + $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'; + + $mail->send(); + echo 'Message has been sent'; } catch (Exception $e) { - echo 'Caught exception: ', $e->getMessage(), "\n"; + echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; } ?> \ No newline at end of file diff --git a/src/components/DogContactForm.tsx b/src/components/DogContactForm.tsx index a27bf85..a8fe33c 100644 --- a/src/components/DogContactForm.tsx +++ b/src/components/DogContactForm.tsx @@ -67,6 +67,7 @@ export default function DogContactForm( if(data.success) { + toast.success('Eine Kopie wurde auch an ' + toEmail + ' geschickt!'); toast.success('Nachricht gesendet!'); } else if(!data.success && data.message)