This was working before, but I had to create a new vps and now I cannot seem to get the mail function working. When I try to send a test email, I get nothing and I do not even see the success or error messages I created.
The error message in my vps log is cryptic to me, it says:
2017/09/23 15:06:47 [error] 22847#22847: *96 FastCGI sent in stderr: "PHP message: PHP Notice: Undefined index: error in /var/www/microurb.com/public_html/index.php on line 295" while reading upstream, client: 73.197.81.232, server: microurb.club, request: "GET /index.php?success=-1 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "microurb.club", referrer: "http://microurb.club/index.php?success=-1"
I have no clue what this could mean.
The form on my index.php file looks like this:
<section class="section-form" id="form">
<div class="row">
<h2>We're happy to hear from you</h2>
</div>
<div class="row">
<form class="contact-form" action="mailer.php" method="post">
<div class="row">
<?php
if ($_GET['success'] == 1) {
echo "<div class=\"form-messages success\">Thank you! Your message has been sent.</div>";
}
if ($_GET['error'] == -1) {
echo "<div class=\"form-messages error\">Oops! Something went wrong. Please try again!</div>";
}
?>
</div>
<div class="row">
<div class="col span-1-of-3">
<label for="name">Name</label>
</div>
<div class="col span-2-of-3">
<input type="text" name="name" id="name" placeholder="Your name" required>
</div>
</div>
<div class="row">
<div class="col span-1-of-3">
<label for="email">Email</label>
</div>
<div class="col span-2-of-3">
<input type="email" name="email" id="email" placeholder="Your email" required>
</div>
And my mailer.php looks like this:
<?php
// Get the form fields, removes html tags and whitespace.
$name = strip_tags(trim($_POST["name"]));
$name = str_replace(array("\r","\n"),array(" "," "), $name);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$message = trim($_POST["message"]);
// Check the data
if (empty($name) OR empty($message) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: http://microurb.club/index.php?success=-1#form");
exit;
}
// Set the recipient email address.
$recipient = "ale@example.com";
// set the email subject.
$subject = "New contact from $name";
// Build the email content.
$email_content = "Name: $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Message: \n$message\n";
// Build the email headers.
$email_headers = "From $name <$email>";
// Send the email
mail($recipient, $subject, $email_content, $email_headers);
// Redirect to the index.html page with success code
header("Location: http://microurb.club/index.php?success=-1#form");
?>
I have refactored this code in several ways and now I am wondering if the issue is whether or not I have to install postfix or sendmail in my server.