Viewing file: contatti_action.php (6.31 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?
include('include_dir.php');
//include($percorsoLingua.'include/include.php');
include($percorso.'aps/include/costanti.php');
include($percorso.'aps/include_cliente/const_cliente.php');
include($percorso.'aps/include/funzioni.php');
include($percorso.'include/costanti.php');
include('include_cliente/const_cliente.php');
include($percorso.'include/multilingua.php');
/*
require($percorso.'include/class.phpmailer.php');
require($percorso.'include/class.smtp.php');
*/
use PHPMailer\PHPMailer\PHPMailer;
require '../include/PHPMailer.php';
require '../include/SMTP.php';
require '../include/Exception.php';
//require_once $percorso.'include/recaptchalib.php';
require_once $percorso.'recaptcha-master/appengine-https.php';
// Initiate the autoloader. The file should be generated by Composer.
// You will provide your own autoloader or require the files directly if you did
// not install via Composer.
require_once $percorso.'recaptcha-master/src/autoload.php';
$nome = isset( $_POST['template-contactform-name'] ) ? $_POST['template-contactform-name'] : '';
$email = isset( $_POST['template-contactform-email'] ) ? $_POST['template-contactform-email'] : '';
$telefono = isset( $_POST['template-contactform-phone'] ) ? $_POST['template-contactform-phone'] : '';
$service = isset( $_POST['template-contactform-service'] ) ? $_POST['template-contactform-service'] : '';
$oggetto = isset( $_POST['template-contactform-subject'] ) ? $_POST['template-contactform-subject'] : 'Richiesta informazioni';
$messaggio = isset( $_POST['template-contactform-message'] ) ? $_POST['template-contactform-message'] : '';
$gRecaptcha = isset( $_POST['g-recaptcha-response'] ) ? $_POST['g-recaptcha-response'] : '';
$lMessaggioOk=true;
if (checkMail($email))
{
$lMessaggioOk=true;
}
else
{
$lMessaggioOk=false;
}
if ( (trim($nome)=='') || (trim($email)=='') || (trim($messaggio)=='') )
{
$lMessaggioOk==false;
}
// your secret key
$secret = "6LcMLL0lAAAAAC4ajbC1eT2He0UfYX23aGIdSNu3";
// empty response
$response = null;
// check secret key
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
if ($_POST["g-recaptcha-response"]) {
// Make the call to verify the response and also pass the user's IP address
$resp = $recaptcha->setExpectedHostname($_SERVER['SERVER_NAME'])->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if ($resp->isSuccess())
{
if ($lMessaggioOk)
MessaggioOk();
else
MessaggioNotOk();
}
else
{
MessaggioNotOk();
}
//var_export($resp);
}
else
{
MessaggioNotOk();
}
//}
function MessaggioNotOk()
{global $nome, $cognome, $email, $telefono, $oggetto, $messaggio;
echo '{ "alert": "error", "message": "Email <strong>could not</strong> be sent due to some Unexpected Error. Please Try Again later.<br /><br /><strong>Reason:</strong><br />' . $mail->ErrorInfo . '" }';
}
function MessaggioOk()
{global $nome, $mobile, $cognome, $email, $telefono, $oggetto, $messaggio, $service;
switch ($service) {
case 0: //nulla
$destinatario = costantiP::EMAIL_CONTATTO_PRINCIPALE;
$servizio = 'Segreteria';
break;
case 1: //museo
$destinatario = costantiP::EMAIL_CONTATTO_PRINCIPALE;
$servizio = 'Museo';
break;
case 2: //archivio
$destinatario = costantiP::EMAIL_ARCHIVIO;
$servizio = 'Archivio';
break;
case 3: //store
$destinatario = costantiP::EMAIL_SHOP;
$servizio = 'Store';
break;
case 4: //affitto
$destinatario = costantiP::EMAIL_CONTATTO_PRINCIPALE;
$servizio = 'Affitto';
break;
case 5: //taverna
$destinatario = costantiP::EMAIL_CONTATTO_PRINCIPALE;
$servizio = 'Taverna';
break;
}
$pretesto = '==========================='.chr(10);
$pretesto .= 'Mittente: '.$nome.chr(10);
$pretesto .= 'Email: '.$email.chr(10);
$pretesto .= 'Telefono: '.$telefono.chr(10);
$pretesto .= 'Servizio: '.$servizio.chr(10);
$pretesto .= '==========================='.chr(10).chr(10);
$messaggioEmail = $pretesto.$oggetto.chr(10).chr(10).$messaggio.chr(10).chr(10);
$mittente = $email;
//$mail = new PHPMailer();
$mail = new PHPMailer;
$mail->SetLanguage('en', '../include/language/');
//echo 'quiiiii';
//$mail->SMTPDebug = 1;
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = 'starttls';
$mail->Host = costantiP::SMTP_HOST; // specify main and backup server
$mail->Port = '587';
$mail->Username = costantiP::SMTP_USER; // SMTP username
$mail->Password = costantiP::SMTP_PWD; // SMTP password
$mail->From = 'segreteria@museomillemiglia.it';
$mail->FromName = "Richiesta dal modulo contatti";
//$mail->AddAddress(costantiP::EMAIL_CONTATTO_PRINCIPALE, costantiP::EMAIL_CONTATTO_PRINCIPALE);
$mail->AddAddress($destinatario, $destinatario);
//$mail->AddAddress('skateo@gmail.com', 'skateo@gmail.com');
$mail->AddReplyTo($mittente, $mittente);
$mail->WordWrap = 80; // set word wrap to 50 characters
$mail->IsHTML(false); // set email format to HTML
$mail->Subject = $oggetto;
$mail->Body = $messaggioEmail;
if($mail->Send()){$message_success = 'Messaggio inviato con <strong>successo</strong>. Verrai ricontattato quanto prima. Grazie';
echo '{ "alert": "success", "message": "' . $message_success . '" }';
}
else
{echo '{ "alert": "error", "message": "Email <strong>could not</strong> be sent due to some Unexpected Error. Please Try Again later.<br /><br /><strong>Reason:</strong><br />' . $mail->ErrorInfo . '" }';
}
unset($mail);
}
function checkMail($toCheck){
$find = "/^[a-zA-Z0-9-_.]+@[a-zA-Z0-9-_.]+.[a-zA-Z]{2,4}$/";
if(!preg_match($find, trim($toCheck))){
return false;
}else{
return true;
}
}?>
|