-1

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("myemail@email.com", "Message via site",
      
      $_POST["insert message here"]. "From: useremail@email.com");
   }
?>

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.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • You need to do a couple things: install a web server (XAMPP, WAMP, etc.) and a [SMTP](https://postmarkapp.com/guides/everything-you-need-to-know-about-smtp). Or simply run your project on a web hosting which allows you to send email messages. – Alexis88 Jun 25 '23 at 17:28
  • 1
    Typo in your form..... method = "post" – James Jun 25 '23 at 17:58

1 Answers1

0

You could start doing something like this, in a HTML file:

<form action="email-sender.php" method="post">
    <label for="name">Name:</label>
    <input id="name" type="text" name="name" required>
    <label for="email">Email:</label>
    <input id="email" type="email" name="email" required>
    <label for="message">Message:</label>
    <textarea id="message" name="message" required></textarea>
    <button type="submit">Submit</button>
</form>

And then you write an PHP file like this:

<?php
//These variables are optional, you can assign the $_POST values to other variables if you want to manipulate the values
$email = $_POST['email'];
$name = $_POST['name'];
$message = $_POST['message'];

mail('myemail@email.com', 'Message Via Website', 'Email sent by ' . $name . ' from ' . $email . " saying:\n" . $message);

//This function redirects to another page
header('Location: myHTMLfile.html');

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.