Modifying Wordpress to send email if your host requires the -f parameter

To increase security on email sent by websites, some web hosts (e.g. require that all mail sent via PHP scripts use the "-f" parameter to ensure that the sending email address is from a domain registered with that host. This "-f" parameter is used to set the envelope sender address when using sendmail. Wordpress does not seem to support the appending of this type of parameter by default. As a workaround, you can edit the Wordpress emailing code directly. You can do this by modifying the function MailSend in the file wp-includes/class-phpmailer.php (search for 'function MailSend').

There is a line in here:

$rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header); 

Change this to: $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header, "-f");

Replacing the dummy email address there with one registered with the host in question. If you are using a plugin to generate emails (such as the cforms II plugin) you will also need to edit the mailing functions there. In cforms, the functions you need to change are in lib_nonajax.php or lib_ajax.php (depending on whether you are using AJAX forms or not). In this case, the lines you need to change are the ones that read,


$sentadmin = @mail($to, encode_header($vsubject), $fmessage.$attached, $headers);


$sentadmin = @mail($to, encode_header($vsubject), $fmessage.$attached, $headers, "-f"); and

$sent = @mail($field_email, encode_header(stripslashes($t[1])), $fmessage, $headers2);


$sent = @mail($field_email, encode_header(stripslashes($t[1])), $fmessage, $headers2, "-f");

As always, there may be a better way to do this - if you know one, let me know!