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. streamline.net) 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 me@mydomain.com");

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);
   
to

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

and

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

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

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

5 Things to consider when making the 15% VAT Rate Change

Well that's put the cat among the pigeons.

5 working days for every retailer in the UK to change their databases, accounting systems and e-commerce websites to reflect a new VAT rate.

We've already had a couple of new customers phone us for help, either with updating their Filemaker Pro databases or Coldfusion websites to reflect the VAT rate change.

If the system has been well designed in the first place, this should be relatively straightforward. But with the VAT rate not having changed since 1991, there is always the chance that a developer has taken a shortcut and hardcoded it somewhere.

The VAT rate should be stored in one global variable that can be simply changed. Hopefully this is in a database field that the system administrator can access - but it may be buried in a preferences or application file in the code somewhere only a developer can find it. Or worse, it may have been hardcoded into calculations all over the place (as we found in one case today).

A few things to be aware of if you are about to embark on the task of changing the VAT rate yourself:

  1. If the VAT rate is stored globally, make sure the VAT rate in use at the time has been stored with historical transactions (or at least the VAT charged has been stored) - and that changing the global rate will not affect reporting of existing transactions.
  2. If the VAT rate is stored globally and is easy to change, your prices will all change appropriately. But you may decide you don't want this - what about all those £9.99s becoming £9.77 ? In this case you may not want to pass the VAT cut on to your customers. You may be able to get round this issue by doing a global search directly in your database for net prices affected and replace them with net prices multiplied by the appropriate fraction to avoid the gross price changing - a bit complicated, but definitely preferable to changing hundreds of prices by hand.
  3. If you are having to change Coldfusion or PHP code, you might just be able to do a search and replace for everywhere the existing rate is mentioned. But remember to search for all the possible variations - 17.5, 0.175, 1.175, 117.5 etc - there are lots of ways to calculate VAT... (oh yeah, and just in case your developer was particularly obtuse, 85.10638297872340425531914893617 - the fraction to work out the net price from a gross price).
  4. Before you change anything, BACKUP, BACKUP, BACKUP, and after you've made the changes, TEST, TEST, TEST.
  5. Keep a note of the changes you've made, cause you're going to need to change it all back in 13 months time...

If you think you might need a hand with any of this for a Coldfusion or PHP e-commerce website, or a Filemaker Pro database, please get in touch or leave a comment below. It looks like it's going to be a busy weekend for everybody...

BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner