?php use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; $ArticleData = json_decode(file_get_contents('a/frontpage/a.json'), TRUE); function OutputErrors($errors) { $output = array(); foreach($errors as $error) { $output[] = '
  • ' . $error . '
  • '; } return ''; } $EmailAlert = FALSE; $MessageAlert = FALSE; $MessageSent = FALSE; // If the visitor submitted an email if (!empty($_POST)) { $email = $_POST['email']; $subject = 'Köp av ' . $SiteTitle; $message = $_POST['message']; $subjects = $_POST['subjects']; // Check if the user have inputed an email or not if (empty($email) OR strlen(trim($email)) == 0) { $errors[] = 'Du måste ange en email adress'; $EmailAlert = true; } // Validate the email and check if it isnt already taken by another user if (!empty($email)) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors[] = 'Email adressen du angav är inte korrekt'; $EmailAlert = true; } } if (strlen(trim($message)) == 0) { $errors[] = 'Du måste skriva ett meddelande'; $MessageAlert = true; } if (strlen($message) > 1000) { $errors[] = 'Meddelandet kan inte vara längre än 1000 tecken, du skrev: ' . strlen($message); $MessageAlert = true; } if (!empty($subjects)) { $MessageSent = TRUE; } if (empty($errors) && !$MessageSent) { require MODULESPATH . '/PHPMailer/src/Exception.php'; require MODULESPATH . '/PHPMailer/src/PHPMailer.php'; require MODULESPATH . '/PHPMailer/src/SMTP.php'; // Instantiation and passing `true` enables exceptions $mail = new PHPMailer(true); try { //Server settings $mail->SMTPDebug = 0; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'jesper@jespera.se'; // SMTP username $mail->Password = 'capDoj-xejxop-8cacqo'; // SMTP password $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 465; // TCP port to connect to //Recipients $mail->setFrom($email, $email); $mail->addAddress("jesper@jespera.se", "jesper@jespera.se"); // Add a recipient // Content $mail->isHTML(true); // Set email format to HTML $mail->CharSet = 'utf-8'; $mail->Subject = htmlspecialchars($subject); $mail->Body = file_get_contents(MODULESPATH . '/email/visitorEmail.html'); $mail->Body = str_replace("{{MESSAGE}}", nl2br(htmlspecialchars($message)),$mail->Body); $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; $mail->send(); $MessageSent = TRUE; } catch (Exception $e) { echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; } } // Send message } // If the visitor submitted an email include SITEHEADER; ?>