Guten Morgen allerseits!
Auf meiner Website ermögliche ich mit Sessions eine Sprachenauswahl.
index.php:
Code
[COLOR=#008000][FONT=Consolas]//Language-Session[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]
[COLOR=#0000ff] if[/COLOR](!isset($_GET[[COLOR=#a31515]"language"[/COLOR]]))
{
[COLOR=#0000ff]if[/COLOR](!isset($_SESSION[[COLOR=#a31515]"language"[/COLOR]]))
{
include([COLOR=#a31515]'_include/lang/de.php'[/COLOR]);
$_SESSION[[COLOR=#a31515]"language"[/COLOR]] = [COLOR=#a31515]'de'[/COLOR];
}
[COLOR=#0000ff]else[/COLOR]
{
include([COLOR=#a31515]'_include/lang/'[/COLOR] . $_SESSION[[COLOR=#a31515]"language"[/COLOR]] . [COLOR=#a31515]'.php'[/COLOR]);
}
}
[COLOR=#0000ff]else[/COLOR]
{
$_SESSION[[COLOR=#a31515]"language"[/COLOR]] = $_GET[[COLOR=#a31515]"language"[/COLOR]];
include([COLOR=#a31515]'_include/lang/'[/COLOR] . $_SESSION[[COLOR=#a31515]"language"[/COLOR]] . [COLOR=#a31515]'.php'[/COLOR]);
}
[/FONT][/COLOR]
[COLOR=#008000][FONT=Consolas]//End of Language-Session
[/FONT][/COLOR]
Alles anzeigen
Nun will ich diese Sprachdateien auch in einem Mailing-Script verfügbar machen, welches nicht direkt in die Website eingebunden, sondern per Ajax angesprochen wird.
Der Ajax-Teil:
Code
[COLOR=#000000][FONT=Consolas][COLOR=#008000]/* ==================================================[/COLOR]
[COLOR=#008000] Contact Form[/COLOR]
[COLOR=#008000]================================================== */[/COLOR]
BRUSHED.contactForm = [COLOR=#0000ff]function[/COLOR](){
$([COLOR=#a31515]"#contact-submit"[/COLOR]).on([COLOR=#a31515]'click'[/COLOR],[COLOR=#0000ff]function[/COLOR]() {
$contact_form = $([COLOR=#a31515]'#contact-form'[/COLOR]);
[COLOR=#0000ff]var[/COLOR] fields = $contact_form.serialize();
$.ajax({
type: [COLOR=#a31515]"POST"[/COLOR],
url: [COLOR=#a31515]"_include/php/contact.php"[/COLOR],
data: fields,
dataType: [COLOR=#a31515]'json'[/COLOR],
success: [COLOR=#0000ff]function[/COLOR](response) {
[COLOR=#0000ff]if[/COLOR](response.status){
$([COLOR=#a31515]'#contact-form input'[/COLOR]).val([COLOR=#a31515]''[/COLOR]);
$([COLOR=#a31515]'#contact-form textarea'[/COLOR]).val([COLOR=#a31515]''[/COLOR]);
}
$([COLOR=#a31515]'#response'[/COLOR]).empty().html(response.html);
}
});
[COLOR=#0000ff]return[/COLOR] [COLOR=#0000ff]false[/COLOR];
});
[/FONT][/COLOR]
[COLOR=#000000][FONT=Consolas]}
[/FONT][/COLOR]
Alles anzeigen
Und hier das aktuelle Mailing-Script, welches übersetzt werden soll:
PHP
[COLOR=#000000][FONT=Consolas][COLOR=#800000]<?php[/COLOR]
header([COLOR=#a31515]'Cache-Control: no-cache, must-revalidate'[/COLOR]);
header([COLOR=#a31515]'Expires: Mon, 26 Jul 1997 05:00:00 GMT'[/COLOR]);
header([COLOR=#a31515]'Content-type: application/json'[/COLOR]);
[COLOR=#0000ff]require_once[/COLOR] ([COLOR=#a31515]'db_connect.php'[/COLOR]);
$statement = $db->query([COLOR=#a31515]'[/COLOR][COLOR=#0000ff]SELECT[/COLOR][COLOR=#a31515] mail_contact [/COLOR][COLOR=#0000ff]FROM[/COLOR][COLOR=#a31515] settings[/COLOR][COLOR=#a31515]'[/COLOR]);
$admin_email = $statement->fetch()[[COLOR=#a31515]'mail_contact'[/COLOR]];
$message_min_length = [COLOR=#09885a]5[/COLOR];
[COLOR=#008000]//PHPmailer v6 Setup[/COLOR]
[COLOR=#0000ff]use[/COLOR] PHPMailer\PHPMailer\PHPMailer;
[COLOR=#0000ff]use[/COLOR] PHPMailer\PHPMailer\Exception;
[COLOR=#0000ff]require[/COLOR] [COLOR=#a31515]'Exception.php'[/COLOR];
[COLOR=#0000ff]require[/COLOR] [COLOR=#a31515]'PHPMailer.php'[/COLOR];
[COLOR=#0000ff]require[/COLOR] [COLOR=#a31515]'SMTP.php'[/COLOR];
[COLOR=#0000ff]class[/COLOR] Contact_Form
{
[COLOR=#0000ff]function[/COLOR] __construct($details, $admin_email, $message_min_length)
{
[COLOR=#0000ff]$this[/COLOR]->name = stripslashes($details[[COLOR=#a31515]'name'[/COLOR]]);
[COLOR=#0000ff]$this[/COLOR]->email = trim($details[[COLOR=#a31515]'email'[/COLOR]]);
[COLOR=#0000ff]$this[/COLOR]->subject = [COLOR=#a31515]'Blechlavine.com - Kontaktnachricht eingegangen'[/COLOR];
[COLOR=#0000ff]$this[/COLOR]->message = stripslashes($details[[COLOR=#a31515]'message'[/COLOR]]);
[COLOR=#0000ff]$this[/COLOR]->admin_email = $admin_email;
[COLOR=#0000ff]$this[/COLOR]->message_min_length = $message_min_length;
[COLOR=#0000ff]$this[/COLOR]->response_status = [COLOR=#09885a]1[/COLOR];
[COLOR=#0000ff]$this[/COLOR]->response_html = [COLOR=#a31515]''[/COLOR];
}
[COLOR=#0000ff]private[/COLOR] [COLOR=#0000ff]function[/COLOR] validateEmail()
{
$regex =[COLOR=#811f3f]'/[/COLOR]^[COLOR=#811f3f]([\w-][/COLOR]+[COLOR=#811f3f](?:\.[\w-][/COLOR]+[COLOR=#811f3f])[/COLOR]*[COLOR=#811f3f])@((?:[\w-][/COLOR]+[COLOR=#811f3f]\.)[/COLOR]*[COLOR=#811f3f]\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)[/COLOR]$[COLOR=#811f3f]/i'[/COLOR];
[COLOR=#0000ff]if[/COLOR] ([COLOR=#0000ff]$this[/COLOR]->email == [COLOR=#a31515]''[/COLOR])
[COLOR=#0000ff]return[/COLOR] [COLOR=#0000ff]false[/COLOR];
$string = preg_replace($regex, [COLOR=#a31515]''[/COLOR], [COLOR=#0000ff]$this[/COLOR]->email);
[COLOR=#0000ff]return[/COLOR] empty($string);
}
[COLOR=#0000ff]private[/COLOR] [COLOR=#0000ff]function[/COLOR] validateFields()
{
[COLOR=#008000]// Check name[/COLOR]
[COLOR=#0000ff]if[/COLOR](![COLOR=#0000ff]$this[/COLOR]->name)
{
[COLOR=#0000ff]$this[/COLOR]->response_html .= [COLOR=#a31515]'<p>'[/COLOR].$lang[[COLOR=#a31515]'contact_errorname'[/COLOR]].[COLOR=#a31515]'</p>'[/COLOR];
[COLOR=#0000ff]$this[/COLOR]->response_status = [COLOR=#09885a]0[/COLOR];
}
[COLOR=#008000]// Check email[/COLOR]
[COLOR=#0000ff]if[/COLOR](![COLOR=#0000ff]$this[/COLOR]->email)
{
[COLOR=#0000ff]$this[/COLOR]->response_html .= [COLOR=#a31515]'<p>'[/COLOR].$lang[[COLOR=#a31515]'contact_erroremail'[/COLOR]].[COLOR=#a31515]'</p>'[/COLOR];
[COLOR=#0000ff]$this[/COLOR]->response_status = [COLOR=#09885a]0[/COLOR];
}
[COLOR=#008000]// Check valid email[/COLOR]
[COLOR=#0000ff]if[/COLOR]( [COLOR=#0000ff]$this[/COLOR]->email &&![COLOR=#0000ff]$this[/COLOR]->validateEmail() )
{
[COLOR=#0000ff]$this[/COLOR]->response_html .= [COLOR=#a31515]'<p>'[/COLOR].$lang[[COLOR=#a31515]'contact_erroremail2'[/COLOR]].[COLOR=#a31515]'</p>'[/COLOR];
[COLOR=#0000ff]$this[/COLOR]->response_status = [COLOR=#09885a]0[/COLOR];
}
[COLOR=#008000]// Check message length[/COLOR]
[COLOR=#0000ff]if[/COLOR](![COLOR=#0000ff]$this[/COLOR]->message || strlen([COLOR=#0000ff]$this[/COLOR]->message) < [COLOR=#0000ff]$this[/COLOR]->message_min_length)
{
[COLOR=#0000ff]$this[/COLOR]->response_html .= [COLOR=#a31515]'<p>'[/COLOR].$lang[[COLOR=#a31515]'contact_errormessage'[/COLOR]].[COLOR=#a31515]'</p>'[/COLOR];
[COLOR=#0000ff]$this[/COLOR]->response_status = [COLOR=#09885a]0[/COLOR];
}
}
[COLOR=#0000ff]private[/COLOR] [COLOR=#0000ff]function[/COLOR] sendEmail()
{
[COLOR=#008000]//PHPmailer v6 Instanz[/COLOR]
$oMailer = [COLOR=#0000ff]new[/COLOR] PHPMailer;
$oMailer->CharSet = [COLOR=#a31515]'UTF-8'[/COLOR];
[COLOR=#008000]// SMTP aktivieren[/COLOR]
$oMailer->isSMTP();
[COLOR=#008000]// SMTP-Server[/COLOR]
$oMailer->Host =[COLOR=#a31515]'smtp.strato.de'[/COLOR];
[COLOR=#008000]// SMTP Authentifizierung aktivieren[/COLOR]
$oMailer->SMTPAuth = [COLOR=#0000ff]true[/COLOR];
[COLOR=#008000]// SMTP Benutzer[/COLOR]
$oMailer->Username = [COLOR=#0000ff]$this[/COLOR]->admin_email;
[COLOR=#008000]// SMTP Benutzer Passwort[/COLOR]
$oMailer->Password = [COLOR=#a31515]'xxxxxx'[/COLOR];
[COLOR=#008000]// Verbindungssicherheit setzen ( SSL und TLS möglich )[/COLOR]
$oMailer->SMTPSecure = [COLOR=#a31515]'ssl'[/COLOR];
[COLOR=#008000]// Verbindungsport festlegen[/COLOR]
$oMailer->Port = [COLOR=#09885a]465[/COLOR];
[COLOR=#008000]// Absender Adresse setzen[/COLOR]
$oMailer->From = [COLOR=#0000ff]$this[/COLOR]->email;
[COLOR=#008000]// Absender Alias setzen[/COLOR]
$oMailer->FromName = [COLOR=#0000ff]$this[/COLOR]->name;
[COLOR=#008000]// Empfänger Adresse und Alias hinzufügen[/COLOR]
$oMailer->addAddress([COLOR=#0000ff]$this[/COLOR]->admin_email, [COLOR=#a31515]'Webmaster Blechlavine'[/COLOR]);
[COLOR=#008000]// HTML aktivieren[/COLOR]
$oMailer->isHTML([COLOR=#0000ff]true[/COLOR]);
[COLOR=#008000]// Betreff[/COLOR]
$oMailer->Subject = [COLOR=#a31515]'Blechlavine.com - Nachricht eingegangen'[/COLOR];
[COLOR=#008000]// Der Nachrichteninhalt als HTML[/COLOR]
$oMailer->Body = [COLOR=#0000ff]$this[/COLOR]->message;
[COLOR=#008000]// Alternativer Nachrichteninhalt für Clients, die kein HTML darstellen[/COLOR]
$oMailer->AltBody = strip_tags($oMailer->Body);
[COLOR=#008000]//PHPmailer v6 Versand prüfen[/COLOR]
[COLOR=#0000ff]if[/COLOR](!$oMailer->send())
{
[COLOR=#0000ff]$this[/COLOR]->response_html .= [COLOR=#a31515]'<p>'[/COLOR].$lang[[COLOR=#a31515]'contact_erroremail'[/COLOR]].[COLOR=#a31515]'</p>'[/COLOR];
[COLOR=#0000ff]$this[/COLOR]->response_status = [COLOR=#09885a]0[/COLOR];
}
[COLOR=#0000ff]else[/COLOR]
{
[COLOR=#0000ff]$this[/COLOR]->response_status = [COLOR=#09885a]1[/COLOR];
[COLOR=#0000ff]$this[/COLOR]->response_html .= [COLOR=#a31515]'<p>'[/COLOR].$lang[[COLOR=#a31515]'contact_success'[/COLOR]].[COLOR=#a31515]'</p>'[/COLOR];
[COLOR=#0000ff]exit[/COLOR];
}
}
[COLOR=#0000ff]public[/COLOR] [COLOR=#0000ff]function[/COLOR] sendRequest()
{
[COLOR=#0000ff]$this[/COLOR]->validateFields();
[COLOR=#0000ff]if[/COLOR]([COLOR=#0000ff]$this[/COLOR]->response_status)
[COLOR=#0000ff]$this[/COLOR]->sendEmail();
$response = array();
$response[[COLOR=#a31515]'status'[/COLOR]] = [COLOR=#0000ff]$this[/COLOR]->response_status;
$response[[COLOR=#a31515]'html'[/COLOR]] = [COLOR=#0000ff]$this[/COLOR]->response_html;
echo json_encode($response);
}
}
$contact_form = [COLOR=#0000ff]new[/COLOR] Contact_Form($_POST, $admin_email, $message_min_length);
$contact_form->sendRequest();
[/FONT][/COLOR]
[COLOR=#800000][FONT=Consolas]?[/FONT][/COLOR][COLOR=#800000][FONT=Consolas]>
[/FONT][/COLOR]
Alles anzeigen
Wie mach ich die Übersetzung möglich?
Vielen Dank für eure Unterstützung!