Skip to content

Commit 8c42d57

Browse files
committed
add php mailer class, sendMail route, vendor directory
1 parent 8f1ba7a commit 8c42d57

81 files changed

Lines changed: 10008 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/php/.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/php/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/php/.idea/php.iml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/php/.idea/php.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/php/.idea/workspace.xml

Lines changed: 178 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/php/classes/mailer.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
require_once '../vendor/autoload.php';
4+
use PHPMailer\PHPMailer\PHPMailer;
5+
6+
class Mailer {
7+
public function sendMail($clientMail, $phone, $message) {
8+
$mail = new PHPMailer(true);
9+
$mail->isSMTP();
10+
$mail->SMTPDebug = 2;
11+
$mail->Debugoutput = 'html';
12+
$mail->Host = 'ncg.home.pl';
13+
$mail->Port = 587;
14+
$mail->SMTPSecure = 'tls';
15+
$mail->CharSet = 'UTF-8';
16+
$mail->SMTPAuth = true;
17+
$mail->Subject = 'Nowa wiadomość ze strony tymdev.pl!';
18+
$mail->msgHTML(
19+
'email klienta: ' . $clientMail . '<br>' .
20+
'numer telefonu klienta:' . $phone . '<br>' .
21+
'wiadomość od klienta:' . $message
22+
);
23+
24+
try {
25+
$mail->send();
26+
return true;
27+
} catch (Exception $e) {
28+
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
29+
}
30+
return false;
31+
}
32+
}

api/php/composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
"phpmailer/phpmailer": "^6.1"
4+
}
5+
}

api/php/composer.lock

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/php/routes/sendMail.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
header("Access-Control-Allow-Headers: Origin,Content-Type,Accept,Authorization");
4+
header("Access-Control-Allow-Origin: *");
5+
header("Access-Control-Allow-Methods: *");
6+
header("Content-Type: application/json");
7+
header("Access-Control-Allow-Credentials: true");
8+
9+
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
10+
http_response_code(200);
11+
die();
12+
}
13+
14+
if(
15+
isset($_POST['email']) && !empty($_POST['email']) &&
16+
isset($_POST['message']) && !empty($_POST['message'])
17+
) {
18+
include_once('../classes/mailer.php');
19+
20+
if(!isset($_POST['phone']) || empty($_POST['phone'])) {
21+
$phone = 'Nie podano.';
22+
} else {
23+
$phone = $_POST['phone'];
24+
}
25+
26+
$mailer = new Mailer();
27+
$mailer->sendMail($_POST['email'], $phone, $_POST['message']);
28+
}

api/php/vendor/autoload.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// autoload.php @generated by Composer
4+
5+
require_once __DIR__ . '/composer/autoload_real.php';
6+
7+
return ComposerAutoloaderInitc04ce69bc01f39f78c6ede676cf37545::getLoader();

0 commit comments

Comments
 (0)