74 lines
2.4 KiB
PHP
74 lines
2.4 KiB
PHP
<?php
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
|
|
// Required files
|
|
require 'phpmailer/src/Exception.php';
|
|
require 'phpmailer/src/PHPMailer.php';
|
|
require 'phpmailer/src/SMTP.php';
|
|
|
|
$settings = array(
|
|
'email_mail' => 'mailing@newwalls.pl',
|
|
'email_host' => 'poczta.s-hosting.pl',
|
|
'email_login' => 'mailing@newwalls.pl',
|
|
'email_password' => 'b9N!x5S#w2',
|
|
'email_port' => 465,
|
|
);
|
|
if (isset($_POST['name'])) {
|
|
$data = $_POST;
|
|
|
|
$name = $data['name'];
|
|
$surname = $data['surname'];
|
|
$email = $data['email'];
|
|
$contact_type = $data['contact_type'];
|
|
$message = $data['text'];
|
|
|
|
$mail = new PHPMailer();
|
|
|
|
// Server settings
|
|
$mail->isSMTP();
|
|
$mail->Host = $settings['email_host'];
|
|
$mail->SMTPAuth = true;
|
|
$mail->Username = $settings['email_login'];
|
|
$mail->Password = $settings['email_password'];
|
|
$mail->SMTPSecure = 'ssl';
|
|
$mail->Port = $settings['email_port'];
|
|
$mail->CharSet = "UTF-8";
|
|
|
|
// Recipients
|
|
$mail -> setFrom( 'mailing@newwalls.pl', 'newwalls - zamówienie specjalne' );
|
|
$mail -> addAddress( 'studio@newwalls.pl' );
|
|
if (!empty($email)) {
|
|
$mail->addAddress($email);
|
|
}
|
|
|
|
// Attach file if exists
|
|
if (isset($_FILES['file']) && $_FILES['file']['error'] == UPLOAD_ERR_OK) {
|
|
$mail->addAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']);
|
|
}
|
|
|
|
// Content
|
|
$mail->isHTML(true);
|
|
$mail->Subject = 'NEWWALLS (zamówienie specjalne)';
|
|
$mail->Body = '<p>Imię: ' . htmlspecialchars($name) . '</p>' .
|
|
'<p>Nazwisko: ' . htmlspecialchars($surname) . '</p>' .
|
|
'<p>E-mail: ' . htmlspecialchars($email) . '</p>' .
|
|
'<p>Kontakt: ' . htmlspecialchars($contact_type) . '</p>' .
|
|
'<p>Wiadomość: ' . nl2br(htmlspecialchars($message)) . '</p>';
|
|
|
|
// Success sent message alert
|
|
if ($mail->send()) {
|
|
echo json_encode(array('status' => 'ok', 'message' => 'Wiadomość została wysłana pomyślnie'));
|
|
exit();
|
|
} else {
|
|
// echo json_encode(array('status' => 'error', 'message' => 'Błąd podczas wysyłania wiadomości: ' . $mail->ErrorInfo));
|
|
// exit();
|
|
echo json_encode(array('status' => 'error', 'message' => 'Błąd podczas wysyłania wiadomości'));
|
|
exit();
|
|
}
|
|
} else {
|
|
echo json_encode(array('status' => 'error', 'message' => 'Brak wymaganych danych'));
|
|
exit();
|
|
}
|
|
?>
|