How can PHP be used to process form submissions and send emails without relying on mailto?
To process form submissions and send emails in PHP without relying on mailto, you can use the PHP `mail()` function to send emails programmatically. This function allows you to set the sender, recipient, subject, and message body of the email. Additionally, you can use PHP to validate and sanitize form inputs before sending the email to prevent security vulnerabilities.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$to = "recipient@example.com";
$subject = "Form Submission";
$message = "Name: " . $_POST['name'] . "\n";
$message .= "Email: " . $_POST['email'] . "\n";
$message .= "Message: " . $_POST['message'];
// Send email
if (mail($to, $subject, $message)) {
echo "Email sent successfully.";
} else {
echo "Email sending failed.";
}
}
?>
Keywords
Related Questions
- How can switching from SMTP to sendmail resolve issues with sending confirmation emails in PHP scripts?
- Are there alternative methods, such as JavaScript, to check for administrator rights if PHP is limited to server-side execution?
- What are the differences between using PDO and sqlsrv for database interactions in PHP, and when should each be used?