Hi all!
Working on creating a contact form that sends e-mail to an e-mail address. I'm THIS close to perfection, however, I notice that not all of the data is being captured.
All it captures is the e-mail address & the message itself. Not the "name" field or the drop-down data.
Any changes I make only results in the e-mail being considered spam.
Here is my code:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$to = "myemail@example.com";
$subject = "Contact Form Submission";
$message = htmlspecialchars($_POST['message']);
$headers = "From: " . htmlspecialchars($_POST['email']);
mail($to, $subject, $message, $headers);
}
?>
Any changes I make only results in the e-mail being considered spam.
Please help!
Top comments (4)
My go to is github.com/PHPMailer/PHPMailer
I wouldn't send emails like this. Just use Laravel or Symfony, even Codeigniter - all have a decent email implementation and you can use a SMTP provider like SES, sendgrid, or Zoho Mail, etc...
This will send an email from your server IP, so it probably has a low reputation and lacks DNS records like SPF, DKIM, and DMARC.
Each of the HTML selects, inputs will be a separate post data key, so this will just take the textarea content, I am assuming:
You need to do something like this:
Lastly, you need to set headers for HTML emails, something like:
What are the changes you made?
Thanks everyone! I wound up going a different route. I went to formsubmit.co/ they do the work for you!
In the interim, I plan to take a PHP course to brush up on my coding!