I have recently been learning HTML, js, CSS, and PHP
through creating web pages and posting them on my apache2 server hosted on my raspberry
pi with a no-ip.com address. My first real project for learning PHP has been creating a
simple form to then send an email to me, but I keep running into the issue of the mail()
function executing without any errors, but not actually sending
emails.
Here is the
form:
action="/FormTesting/sendMail.php" method="post">
Name:
/>
Email:
/>
Message:
/> required>
Subject:
name="subject" value="Hello!">Hello!
value="Whats up">Whats Up!
name="submit"
value="Submit">
Here
is the PHP file reference in the form's 'action'
attribute:
if($_SERVER["REQUEST_METHOD"]
== "POST") {
$to = "myExampleEmail@gmail.com";
$name =
$_POST["name"];
$email = $_POST["email"];
$message =
$_POST["message"];
$subject = $_POST["subject"];
echo
$name;
echo $email;
echo $message;
echo
$subject;
$headers = array("From: " .
$email,
"Reply-To: " . $to,
"X-Mailer: PHP/" .
PHP_VERSION);
mail($to, $subject, $message,
$header);
} else {
echo
$_SERVER["REQUEST_METHOD"];
}
?>
I
understand that this question has been asked before, and I have tried most of the
methods set out by other answers, but I still can't seem to get the PHP mail() function
to work. The best information I have is that I have to do some kind of install or
formatting on the server itself to allow for emails to be sent, but I have yet to find
it well documented and/or explained. (i.e phpMailer? - but still...
how?)
EDIT:
I
checked the return value of the mail function . . .
if(mail("myExampleEmail@gmail.com", "subject", "message", $headers)) {
echo
"TRUE";
}else {
echo "FALSE";
}
. . . and it turns
out to be returning false. I assume that means it is an error in my code,
then?
EDIT:
Apparently
I wasn't clear when I said I did research before posting this question. I tried
everything that was given as an answer to the question that mine was a closed as a
"duplicate" of, hence me asking, the question anyway.
No comments:
Post a Comment