insert newsletter form in database

This commit is contained in:
Alexandre L 2023-04-22 15:41:53 -04:00
parent b5a0a49998
commit 63cd5cd605
3 changed files with 8 additions and 19 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/config/PRIVATE/*
!/config/PRIVATE/*.example

View File

@ -1,6 +0,0 @@
<?php
$_ENV['newsletter_url_fr'] ='';
$_ENV['newsletter_url_en'] ='';
?>

View File

@ -1,22 +1,15 @@
<?php <?php
require_once $_SERVER['DOCUMENT_ROOT'].'/config/PRIVATE/NEWSLETTER.php'; require_once $_SERVER['DOCUMENT_ROOT'].'/config/PRIVATE/DB.php';
$lang_folder = $_GET['newsletter-language']=="fr"?"/pages/fr/":"/pages/en/"; $lang_folder = $_GET['newsletter-language']=="fr"?"/pages/fr/":"/pages/en/";
$contact_form_url = $_GET['newsletter-language']=="fr"?$_ENV['newsletter_url_fr']:$_ENV['newsletter_url_en'];
if(!str_contains($_GET['newsletter-email'], "@") || !str_contains($_GET['newsletter-email'], ".") || strlen($_GET['newsletter-email']) < 6 || $_GET['newsletter-email-2'] != "") { if(!filter_var($_GET['newsletter-email'], FILTER_VALIDATE_EMAIL) || $_GET['newsletter-email-2'] != "") {
header('Location: '.$lang_folder.'err/general.html'); header('Location: '.$lang_folder.'err/general.html');
die(); die();
} }
$ch = curl_init($contact_form_url);
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode('email').'='.urlencode($_GET['newsletter-email'])); $insert_email = $pdo->prepare('INSERT IGNORE INTO newsletter(email,language) VALUES (?,?)');
curl_setopt($ch, CURLOPT_HEADER, 0); $insert_email->execute(array($_GET['newsletter-email'],$_GET['newsletter-language']));
curl_setopt($ch, CURLOPT_POST, 1); if($insert_email->rowCount()==1){
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode==200){
header('Location: '.$lang_folder.'confirmation.html'); header('Location: '.$lang_folder.'confirmation.html');
die(); die();
} }