setFrom('myemail@example.com', 'Sender Name'); $mail->addAddress('recipient@example.com', 'Recipient Name'); $mail->Subject = 'Example Email with Reply-To'; $mail->Body = 'Hello, world!'; // Add a reply-to address $mail->addReplyTo('replyto@example.com', 'Reply-To Name'); // Send the email if (!$mail->send()) { echo 'Error: ' . $mail->ErrorInfo; } else { echo 'Email sent!'; } ?>
setFrom('myemail@example.com', 'Sender Name'); $mail->Subject = 'Example Email with Reply-To'; $mail->Body = 'Hello, world!'; // Add multiple recipients and reply-to addresses $recipients = array( 'recipient1@example.com' => 'Recipient 1 Name', 'recipient2@example.com' => 'Recipient 2 Name' ); $replyTos = array( 'replyto1@example.com' => 'Reply-To 1 Name', 'replyto2@example.com' => 'Reply-To 2 Name' ); foreach ($recipients as $email => $name) { $mail->addAddress($email, $name); $mail->addReplyTo($replyTos[$email], $name); } // Send the emails if (!$mail->send()) { echo 'Error: ' . $mail->ErrorInfo; } else { echo 'Emails sent!'; } ?>Both of these examples use the PHPMailer library, which is an open-source library available under the MIT license. The library can be included in your project using composer or downloaded from the GitHub repository.