Search code examples
wordpressemailwp-mail

Set reply-to address in wp_mail header


I use wp_mail to send notifications out of my WordPress theme. How can i add a reply-to address to the follwing wp_mail script:

$recipient  = "[email protected]";
$headers = array('Content-Type: text/html; charset=UTF-8','From: MyWebsite <'[email protected]'>');
$message = 'Here is the sent message';
        
wp_mail( $recipient, 'Here comes the Subject', $message, $headers );     

   

Solution

  • You can set the reply-to address inside of the $headers array. It needs to have the email address inside of <> and I would suggest using a name to make sure everything works fine.

    $headers[] = 'Reply-To: Firstname Lastname <[email protected]>';

    I added a subject for your email. So your code would look like:

    $recipient  = "[email protected]";
    $subject = "Your subject";
    $message = "Here is the sent message";
    $headers = array(
        'Content-Type: text/html; charset=UTF-8',
        'From: MyWebsite <[email protected]>',
        'Reply-To: Firstname Lastname <[email protected]>'
    );
    
    wp_mail( $recipient, $subject, $message, $headers );