0

So, I am trying to add "reply-to" in the order email using the billing_email

Here is what I have so far but the code is not written well and I am not sure how to change it.

Here is the original:

 public function send( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "" ) {
    $email = new WC_Email();
    $email->send( $to, $subject, $message, $headers, $attachments );
}

Then I edited to the following:

public function send( $to, $subject, $message, $attachments = "", $order ) {
    $headers = array( "Reply-To:  <?php echo $order->billing_email; ?>" );
    $email = new WC_Email();
    $email->send( $to, $subject, $message, $headers, $attachments );
}

Any suggestions?

Thanks

2

Not sure what the WC_Email class does exactly, but if the $headers argument is an array of headers, then you're almost there. To interpolate a variable value into a string in PHP you don't have to do the <?php ... stuff because it'll be rendered as is. Instead, you can use:

$headers = array( "Reply-To: {$order->billing_email}" );

Or:

$headers = array( 'Reply-To: ' . $order->billing_email );

Or:

$headers = array( sprintf( 'Reply-To: %s', $order->billing_email ) );

Also, if the billing e-mail address is user input, don't forget to validate it with is_email() and/or sanitize it with sanitize_email().

Hope that helps.

| improve this answer | |
  • It looks like $headers asks for a string - see WC_Email source – but then passes whatever you give it, without alteration, to wp_mail (that can accept a string or array.) – William Turrell Apr 4 '15 at 11:34
  • Yeah, wp_mail() takes both strings an arrays for headers so it should be fine. Otherwise just implode with \r\n and pass as a string. – kovshenin Apr 4 '15 at 15:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.