PHP Code to add CC and Reply-To in additional_headers

[ad_1]

I have a form that uses code within functions.php that takes emails as an array from an ACF field and assigns it to the mail properties’ additional_headers key. It also changes the recipient to that of another ACF field.

$cc_users = $cc ? 'Cc: ' . implode(', ', $cc) : '';

$contact_form->set_properties( array(
   'mail' => array(
       'recipient' => $recipient_email,
       'additional_headers' => $cc_users,
       'subject' => $contact_form->prop('mail')['subject'],
        'body' => $contact_form->prop('mail')['body'],
    ),
) );

This code currently works as expected.

I however, I would like to add Reply-To to this form so that users click reply and have it go to to the submitter.

How can I modify this code? Adding this to the code does not work

$reply_to_user = $posted_data['Email'];
$reply_to = ' Reply-To: ' . $reply_to_user;

$cc_users = $cc ? 'Cc: ' . implode(', ', $cc) : '';

$contact_form->set_properties( array(
   'mail' => array(
       'recipient' => $recipient_email,
       'additional_headers' => $reply_to . $cc_users,
       'subject' => $contact_form->prop('mail')['subject'],
        'body' => $contact_form->prop('mail')['body'],
    ),
) );

I can see that the $reply_to variable is be populated correctly. But when I try to submit a form it errors out. Logs show that it thinks the cc email is part of the Reply-To address.

E.g. “Reply-To:” “[email protected] Cc: [email protected]

How can I escape the Reply-To correctly so that the CC can proceed?

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer