Clear all ReplyTo recipients.
public clearReplyTos ( ) : void | ||
return | void |
use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; $mail = new PHPMailer(true); // Enable SMTP debugging $mail->SMTPDebug = 2; // Set the hostname of the mail server $mail->Host = 'smtp.example.com'; // Set the SMTP port number - likely to be 25, 465 or 587 $mail->Port = 25; // Whether to use SMTP authentication $mail->SMTPAuth = true; // Username to use for SMTP authentication $mail->Username = 'user@example.com'; // Password to use for SMTP authentication $mail->Password = 'secret'; // Set who the message is to be sent from $mail->setFrom('from@example.com', 'Mailer'); // Set an alternative reply-to address $mail->addReplyTo('replyto@example.com', 'Reply-to'); // Clear any previous reply-to addresses $mail->clearReplyTos(); // Set who the message is to be sent to $mail->addAddress('recipient@example.com', 'Recipient'); // Set the subject line $mail->Subject = 'PHPMailer ClearReplyTos example'; // Set the body message $mail->Body = 'This is an example email sent with PHPMailer ClearReplyTos method.'; // Try to send the email if (!$mail->send()) { echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message sent!'; }In the code example above, the ClearReplyTos method is used after adding a reply-to address to the email, in order to clear any previous reply-to addresses. This ensures that only the specified reply-to address will be used.