I’m trying to figure out how to have an email system on a site I’m building. The goal is three input spaces (their name, email, and message) and the system take that input and send it in an email. Or even if there’s a way to just get the email/message sent from the site to my email.
I was also wondering if there’s a way to edit the text box or anything for this system using CSS, if so, I’ll toy with it and figure it out. If not, any suggestions of how to go about it?
I tried writing a .php script and here’s what I wrote:
<?php
if($_POST["message"]) {
mail("[email protected]", "Message via site",
$_POST["insert message here"]. "From: [email protected]");
}
?>
And the HTML that gets the form box:
<form method "post" action = "emailform.php">
<textarea name = "message"></textarea>
<input type = "submit">
</form>
However, this ends up saving the .php script to my computer and no email or anything is sent. I know I’m doing something wrong here, but this was at the very least supposed to be a test to see if the system works with the remaining input boxes and tuning to be done later.
2
Answers
You could start doing something like this, in a HTML file:
And then you write an PHP file like this:
After this you can test it by installing the apache server on your device and then install the PHP module manually, or you could install an easy to use Web Server like XAMPP, download it here: https://www.apachefriends.org/download.html
Then if you choose to use XAMPP, you just need to configure the SMTP server on the php.ini and sendmail.ini files or in the case you chose the first option, you’ll need to install sendmail PHP module and then do a bit more complicated configuration also involving the php.ini and sendmail.ini files.
Hope this helps.
I also recommend PHPMailer library (https://github.com/PHPMailer/PHPMailer) since it is easy to use.