I am writing code for a site that was done in Laravel, I know that it is not recommended to write PHP code within the Blade template, but in this instance I have limited time available.
@php
if($_POST["submit"]){
$name = $_POST["name"];
$email = $_POST["email"];
$missingName = "<p><strong>Please eneter your name.</strong></p>";
$invalidEmail = "<p><strong>Invalid Email.</strong></p>";
if($name){
$name = filter_var($name, FILTER_SANITIZE_STRING);
}else{
$errors .= $missingName;
}
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
$email = filter_var($email, FILTER_VALIDATE_EMAIL);
if(filter_var($email, FILTER_VALIDATE_EMAIL)){
}else{
$errors .= $invalidEmail;
}
if($errors){
$resultMessage = '<div class="alert alert-danger">' . $errors .'</div>';
}else{
$to = "leads@relevant.systems";
$subject = "DijiJock update request form.";
$message = "<html>
<body>
<h2 style='color:black'>DijiJock update request form.</h2>
<p style='color:green'>Name: $name</p>
<p style='color:green'>Email: $email</p>
<p style='color:black'>$name has requested DijiJock updates, please forward all updates to $email.</p>
</body>
</html>";
$headers = "Content-type: text/html";
if(mail($to, $subject, $message, $headers)){
$resultMessage = '<div class="alert alert-success">Thank you for the meesage!</div>';
}else{
$resultMessage = '<div class="alert alert-warning">Email not sent! Please try again later.</div>';
}
}
echo $resultMessage;
}
@endphp
The PHP code in the middle does not work?