Files
newwalls.pl/email-pattern.php
2024-12-17 13:43:22 +01:00

72 lines
2.1 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'];
$image = $data['image'];
$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 - Wzór' );
$mail -> addAddress( 'studio@newwalls.pl' );
if (!empty($email)) {
$mail->addAddress($email);
}
if (!empty($image)) {
$image_content = file_get_contents($image);
$image_name = basename(parse_url($image, PHP_URL_PATH));
$mail -> addStringAttachment($image_content, $image_name);
}
// Content
$mail->isHTML(true);
$mail->Subject = 'NEWWALLS (Wzór)';
$mail->Body = '<p>Imię: ' . htmlspecialchars($name) . '</p>' .
'<p>Nazwisko: ' . htmlspecialchars($surname) . '</p>' .
'<p>E-mail: ' . htmlspecialchars($email) . '</p>' .
'<p>Kontakt: ' . htmlspecialchars($contact_type) . '</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'));
exit();
}
} else {
echo json_encode(array('status' => 'error', 'message' => 'Brak wymaganych danych'));
exit();
}
?>