Hallo
Das Kontaktformular enthält zahlreiche Pflichtfelder. Diese sollten beim Abschicken des Formulars ebenfalls übermittelt werden. Zum Beispiel sind dies...
- Name
- Vorname
- Telefon
Per E-mail erhalte ich die Nachricht, dass jemand das Kontaktformular ausgefüllt hat, jedoch ohne diese obenstehenden zusätzlichen Informationen. Sieht jemand evt. im Code woran das liegen könnte?
Vielen Dank
PHP
<?php
error_reporting(E_ALL);
ini_set("display_errors", true);
function checkForError($text, $errors)
{
if (in_array($text, $errors))
echo "<span style='color:#FF0000'>$text*</span>\n";
else
echo "$text*\n";
}
// Variablen initialisieren
$company = $salutation = $firstname = $lastname = $email = $street = "";
$city = $phone = $fax = $messagetopic = $message = "";
$errorText = "";
// Fehler-Array initialisieren
$errors = array();
// Script wurde vom Formular aufgerufen??
if (isset($_POST['company']))
{
// Ja, also Ueberpruefung der Daten
$validEmail = true;
// config laden
include ("./mailconfig.inc.php");
if (! checkValue ($_POST['company'], $company))
$errors[] = "Company";
if (! checkValue ($_POST['firstname'], $firstname))
$errors[] = "First Name";
if (! checkValue ($_POST['lastname'], $lastname))
$errors[] = "Last Name";
if (! checkValue ($_POST['email'], $email))
$errors[] = "E-Mail";
if (! checkValue ($_POST['phone'], $phone))
$errors[] = "Phone";
if (! checkValue ($_POST['message'], $message))
$errors[] = "Message";
// Keine Pflichtfelder
$salutation = trim($_POST['salutation']);
$city = stripslashes(trim($_POST['city']));
$street = stripslashes(trim($_POST['street']));
$fax = stripslashes(trim($_POST['fax']));
$topic = isset($_POST['messagetopic']) ? stripslashes(trim($_POST['messagetopic'])) : "";
if (!empty($email))
{
$validEmail = checkMail($email);
}
// Fehler vorhanden
if (count($errors))
{
$errorText = "Fields marked with an asterisk * are mandatory: " . implode(", ", $errors);
}
// Check der MailAdresse erfolgreich?
if (!$validEmail)
{
$errorText .= (strlen($errorText)) ? "<br /><br />" : "";
$errorText .= "E-mail address invalid";
}
// Wenn jetzt kein Fehlertext vorhanden ist, kann die Mail raus,
if (!strlen ($errorText))
{
// Keine Fehler gefunden
// phpMailer laden
include ("mail/class.phpmailer.php");
// Hoang - Add code in here
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = PHPMAILER_HOST; // specify main and backup server
$mail->Port = 465; // set the port to use
$mail->charset="utf-8";
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = 'ssl';
$mail->Username = PHPMAILER_USER; // your SMTP username or your gmail username
$mail->Password = PHPMAILER_PASSWORD; // your SMTP password or your gmail password
$to=PHPMAILER_TO; // Recipients email ID
$name='Administrator'; // Recipient's name
$mail->From = $email;
$mail->FromName = $firstname; // Name to indicate where the email came from when the recepient received
$mail->AddAddress($to,$name);
$mail->WordWrap = 200; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = PHPMAILER_SUBJECT;
$emailTemplate='<br/>Hello administrator
<br/>Someone filled out the contact form. Here are the details...
<br/>Company: '.$company.'
<br/>First name: '.$firstname.'
<br/>Last name: '.$lastname.'
<br/>From : '.$firstname.' '.$lastname.'
<br/>Contact email : '.$email.'
<br/>Phone: '.$phone.'
<br/>Address: '.$street.' '.$city.'
<br/>Fax: '.$fax.'
<br/>Subject: '.$topic.'
<br/>Message text:'.$message;
$mail->Body = $emailTemplate; //HTML Body
//$mail->AltBody = $txt; //Text Body
//$mail->SMTPDebug = 2;
if(!$mail->Send())
{
$errorText = "Transmission error, please try again later";
echo "<h1>Message erro: " . $mail->ErrorInfo . '</h1>';
}
else
{
//add $mstp for thank you contact in each case
$mstp=$_POST['messagetopic'];
if($mstp=="General_Inquiry")
{
header("Location:thanks-contact.html");
exit;
}
if($mstp=="Service_Feedback")
{
header("Location:thanks-contact1.html");
exit;
}
if($mstp=="Suggestions_Complaints")
{
header("Location:thanks-contact2.html");
exit;
}
else {
header("Location:thanks-contact.html");
exit;
}
}
}
}
?>
Alles anzeigen