Add reply to in php mail handler
To add a reply-to address in a PHP mail handler, you can use the Reply-To
header in the email message. Here's an example of how you can do this:
<?php
// Set the reply-to address
$reply_to = '[email protected]';
// Set the email message
$message = 'Hello, this is an example email';
// Set the email subject
$subject = 'Example Email';
// Set the email from address
$from = '[email protected]';
// Create the email headers
$headers = array(
'From' => $from,
'Reply-To' => $reply_to,
'Subject' => $subject
);
// Send the email
mail('[email protected]', $subject, $message, implode("\r\n", $headers));
?>
In this example, the Reply-To
header is set to [email protected]
, which means that when the recipient replies to the email, the reply will be sent to [email protected]
instead of the original sender's email address.
You can also use the addReplyTo
method of the Swift_Mailer
class in the SwiftMailer library to set the reply-to address:
<?php
// Set the reply-to address
$reply_to = '[email protected]';
// Create a new Swift_Message object
$message = Swift_Message::newInstance();
// Set the email message
$message->setBody('Hello, this is an example email');
// Set the email subject
$message->setSubject('Example Email');
// Set the email from address
$message->setFrom(array('[email protected]' => 'Sender Name'));
// Add the reply-to address
$message->addReplyTo($reply_to);
// Create a new Swift_Mailer object
$mailer = Swift_Mailer::newInstance();
// Send the email
$mailer->send($message);
?>
In this example, the addReplyTo
method is used to set the reply-to address to [email protected]
.