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 steps can be taken to transition from using MCrypt to OpenSSL or other modern PHP-based libraries for encryption, especially when updating both a website and a mobile app for compatibility?
- What are the best practices for handling special characters when passing parameters to external applications in PHP?
- What security considerations should be taken into account when uploading files to a remote server using PHP?