How can PHP mailer be configured to prevent recipients from replying to their own emails?
To prevent recipients from replying to their own emails using PHP mailer, you can set the "Reply-To" header to a different email address than the recipient's address. This way, when the recipient hits reply, the email will be sent to the specified email address instead.
<?php
use PHPMailer\PHPMailer\PHPMailer;
// Create a new PHPMailer instance
$mail = new PHPMailer();
// Set the sender's email address and name
$mail->setFrom('sender@example.com', 'Sender Name');
// Set the recipient's email address and name
$mail->addAddress('recipient@example.com', 'Recipient Name');
// Set a different email address for replies
$mail->addReplyTo('replyto@example.com', 'Reply To Name');
// Set the email subject and body
$mail->Subject = 'Subject';
$mail->Body = 'Email body';
// Send the email
if ($mail->send()) {
echo 'Email sent successfully';
} else {
echo 'Email could not be sent';
}
?>
Keywords
Related Questions
- What are the best practices for handling JSON data in PHP to avoid decoding errors?
- How can PHP developers avoid issues with database design and normalization when working with multiple data entries in a single table?
- What are some common pitfalls when using jQuery and PHP together in a web development project?