I'm using Vlucas library to set up ENVs and I followed the guide from a readme file but don't understand why it's not working.
I don't get a php error log, just get redirected to a 505 page. Before using Vlucas, I recieved PHP error log and it's echo message.
Script is working fine with hard code.
.env file is placed inside the root directory.
I don't get a php error log, just get redirected to a 505 page. Before using Vlucas, I recieved PHP error log and it's echo message.
Script is working fine with hard code.
.env file is placed inside the root directory.
PHP:
use Dotenv\Dotenv;
$dotenv = Dotenv\Dotenv::createImmutable("../");
$dotenv->load();
$mail->Username = $_ENV["email"];
$mail->Password = $_ENV["password"];
Full script:
<?php
if (isset ($_SERVER ["HTTPS"]) && $_SERVER ["HTTPS"] !== "off") {
header("Strict-Transport-Security: max-age=31536000; includeSubDomains; preload");
header("Content-Security-Policy: default-src 'self';
script-src 'self' https://www.google-analytics.com https://ssl.google-analytics.com https://www.googletagmanager.com;
img-src 'self' https://www.google-analytics.com;
connect-src 'self' https://www.google-analytics.com;");
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$industry = filter_input(INPUT_POST, "industry", FILTER_SANITIZE_SPECIAL_CHARS);
$purpose = filter_input(INPUT_POST, "purpose", FILTER_SANITIZE_SPECIAL_CHARS);
$info = filter_input(INPUT_POST, "info", FILTER_SANITIZE_SPECIAL_CHARS);
$select = filter_input(INPUT_POST, "webType", FILTER_SANITIZE_SPECIAL_CHARS);
$webPurpose = filter_input(INPUT_POST, "webPurpose", FILTER_SANITIZE_SPECIAL_CHARS);
$name = filter_input(INPUT_POST, "name", FILTER_SANITIZE_SPECIAL_CHARS);
$clientEmail = filter_input(INPUT_POST, "email", FILTER_SANITIZE_EMAIL);
}
if (!filter_var($clientEmail, FILTER_VALIDATE_EMAIL)) {
die("Invalid email.");
}
require "../vendor/autoload.php";
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use Dotenv\Dotenv;
$dotenv = Dotenv\Dotenv::createImmutable("../");
$dotenv->load();
$mail = new PHPMailer();
$mail->isSMTP();
$mail->isHTML(true);
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->SMTPAuth = true;
$mail->Username = $_ENV["email"];
$mail->Password = $_ENV["password"];
$mail->setFrom("[email protected]");
$mail->addAddress("[email protected]");
$mail->Subject = "New Submission!";
$mail->Body = "Industry - " . $industry . "<br>" . "Purpose - " . $purpose . "<br>" . "Additional information - " . $info . "<br>" . "Web type - " . $webPurpose . "<br>" . "Management - " . $managment . "<br>" . "Name - " . $name . "<br>" . "Email - " . $clientEmail;
if ($mail->send()) {
header("location: ../mail_submitted.html");
exit();
} else {
echo "Sorry, something went wrong. You can try submitting again, or contact me directly at [email protected]";
};