Are there alternative methods to achieve the same functionality as an indirect mailto link in PHP?
When using an indirect mailto link in PHP, the email address is not directly visible in the HTML source code, which can help prevent email harvesting by spambots. An alternative method to achieve the same functionality is to use a server-side script to process the form submission and send the email without exposing the email address in the HTML.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$to = "recipient@example.com";
$subject = "Contact Form Submission";
$message = $_POST["message"];
$headers = "From: " . $_POST["email"];
if (mail($to, $subject, $message, $headers)) {
echo "Email sent successfully";
} else {
echo "Email sending failed";
}
}
?>
Keywords
Related Questions
- What are best practices for defining constructors and variables within PHP classes?
- How can PHP developers optimize their code to avoid long delays and improve user experience?
- What are some common pitfalls when working with forms and data editing in Silex applications, as seen in the provided code snippet?