I am trying to send mail from a PHP page. I don't get any errors, but it doesn't echo the validation error/success messages I included in the code. I am trying to send from Cloud9, which may be impossible, but shouldn't it at least display my success/error message?
[UPDATE] Now it does display my error messages, but every time I submit it, even though I input the needed data. And no information weather the sending failed or not.
PHP:
<?php
include 'includes/mail.php';
?>
<!DOCTYPE html>
...
<form action="?" method="post">
<input name="contact-name" type="text" placeholder="Ime" class="text-input">
<input name="contact-mail" type="email" placeholder="Email" class="text-input">
<textarea name="contact-text" placeholder="Poruka" class="text-input"></textarea>
<p id="submit-btn">
<button type=submit>
<img src="img/lmbtn.png" alt="submit button">
<span class="noselect">POŠALJI</span>
</button>
</p>
<?php
if (empty($errors) === true) {
if(isset($contact_text, $contact_name, $contact_mail)) {
$subject = "Mail from " . $contact_name ." via www.mysite.com";
$headers = "From: " . $contact_mail;
$sent = mail($to, $subject, $contact_text, $headers);
if ($sent) {
echo "<p>Poruka je poslata!</p>";
} else {
echo "<p>I dalje baguje.</p>";
}
}
} else {
?>
<ul>
<?php
foreach ($errors as $error) {
echo "<li>", $error, "</li>";
}
?>
</ul>
<?php
}
?>
</form>
...
And the included mail.php:
<?php
$to = "mymail@gmail.com";
if (isset($_POST['contact-name'], $_POST['contact-mail'], $_POST['contact-text'])) {
if (empty($_POST['contact-name'])) {
$errors[] = "Molimo unesite Vaše ime";
} else {
$contact_name = htmlentities($_POST['contact-name']);
}
if (empty($_POST['contact-mail'])) {
$errors[] = "Molimo unesite Vašu email adresu.";
} else if (strlen($_POST['contact-mail']) > 60) {
$errors[] = "Vaša email adresa je predugačka.";
} else if (filter_var($_POST['contact-mail'], FILTER_VALIDATE_EMAIL) === false ) {
$errors[] = "Unesite validnu email adresu.";
} else {
$contact_mail = "<" . htmlentities($_POST['contact-mail']) . ">";
}
if (empty($_POST['contact-text'])) {
$errors[] = "Molimo unesite poruku.";
} else {
$contact_text = htmlentities($_POST['contact-text']);
}
}
?>
I did not include css or javascript, I guess they are not relevant. JQuery just resets the form after submitting it. Any help, I tried both stackoverflow and google?