I wish to use the wp_mail_from hook to change the from email address submitted through a form which sends an invitation to a friend by email (I am writing my own plugin to do this).
I am using the following code to at present but I cannot see what I am doing wrong as the from email address is not set at all and goes to the default:
function() {
$this->from_email = $_POST['your_email'];
add_filter( 'wp_mail_from', array( $this, 'set_from_email' ) );
wp_mail( $to, $subject, $message);
}
function set_from_email() {
return $this->from_email;
}
As far as I can tell this should work flawlessly and out of the box but I have tried for hours at no avail hence, my question.
FYI I am using this function inside a class but I do not think that should change anything.
Many thanks, nav

$from_mailthrough … and expect a visible change? – toscho♦ Mar 12 '12 at 14:17add_action()andadd_filter()worked the same way. I have modified my code above. As far as I know the above should work but I am still only getting the old from address when email is sent. – navanitachora Mar 12 '12 at 15:43$_POST['your_email']set? Put the following into your functionset_from_email():print '<pre>' . htmlspecialchars( print_r( $_POST, TRUE ) ) . '</pre>';exit;– toscho♦ Mar 12 '12 at 18:02