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!

Making folders writable for PHP when using a Windows IIs server

Many people come across problems using content management systems like Wordpress and Joomla on Windows Servers. One of the problems is folder permissions when you try to upload images or other content.

There are thousands of tutorials out there on how to fix this on Linux servers - chmod the properties of the folder to '777' - but what can you do when you are using a Windows server running IIs?

The error message I was getting in Wordpress was:

Unable to create directory C:\Inetpub\vhosts\mydomain.com\httpdocs/wp-content/uploads/2008/04. Is its parent directory writable by the server?

You may get a similar message from Mambo, Joomla or other content management systems.

In the case of Wordpress, the wp-content folder needs to be writable to IIs - or more specifically the internet user on your server. So how do you do this on Windows? Like all these things, its only easy when you know how.

Assuming you have access to the server e.g. by remote desktop:

  1. Navigate to the wp-content directory. This will most likely be in inetpub/wwwroot/yourdomain or a similar folder in the main web root.
  2. Right-click on the folder, select Properties, and then the 'Security' tab.
  3. This will show a list of the users with rights on your machine. You need to determine which one is used by the IIs process to serve web pages - usually the name in brackets after the username will be prefixed IUSR. In our case, as we are running Plesk to manage our server, the username is Plesk IIS User (ServerName/IUSR_mydomain)

  4. Folder Permissions for IIs user
  5. The only permissions set for this user will probably be the 'List Folder Contents'. You need to add the 'Write' permission, by clicking that box.
  6. Click 'Apply'.
  7. You're done (hopefully).

If you have the Plesk Control Panel, you can set these permissions directly in Plesk without having to remote desktop to the server:

  1. Click Domains, then the relevant domain, then File Manager. Navigate through the folders so you can see the appropriate directory name
  2. Click on the yellow padlock icon ('Change Permissions for Directory')
  3. Padlock

  4. Again choose the appropriate IIs user (the one with IUSR_ in the name)
  5. Click the 'Write' option
  6. Click OK.
  7. Permissions

Please let me know if you found this useful.

URL issues running Wordpress with Plesk SitePreview

If you are having trouble setting up a Wordpress installation with Plesk's Sitepreview, the following may help (and may also apply to other systems that give you a temporary URL to test sites before they go live).

Plesk is a piece of software which provides a straightforward front-end to manage a webserver, and is used by many ISPs to allow customers to manage their own servers. SitePreview is a function of the Plesk control panel which allows you to view a site via a temporary URL before it goes live. This way you and your clients can view and tweak the site before you release it to the wild by putting it on a published URL.

The normal URL format which Plesk uses for SitePreview is of the form:

http://xxx.xxx.xxx.xxx/$sitepreview/mydomain.com/

where xxx.xxx.xxx.xxx is the IP address of the server, and mydomain.com is the name of the site in Plesk (and the ultimate permanent URL).

The problem with viewing a Wordpress site at a SitePreview URL is that Wordpress strips out the $ (dollar) sign, and other special characters, from URLs. This is normally sensible behaviour as the dollar sign would normally not appear in URLs, but it breaks SitePreview, as it begins to return URLs like

http://xxx.xxx.xxx.xxx/sitepreview/mydomain.com/

(note no $ sign), which will give you a 404 Page Not Found error.

The first place I noticed this was when saving the main settings page.

When you save this page, Wordpress strips out the $ from the two URL fields. I haven't looked for the code which does this, but it is easily fixed by using PHPMyAdmin to edit the wp_options table in your Wordpress database (the wp_ may be something else depending on the table prefix you set for your tables in the wp-config.php file). The two records in this table which you have to correct are the ones where - option_name = 'home' - option_name = 'siteurl'

The second place you may have a problem is when using the admin screens. When Wordpress creates the URLs for the javascript files which are required for the 'Visual' mode of the page editor to work, it again strips out those dollar characters.

This issue can be resolved by editing the function clean_url, currently found in wp-includes/formatting.php

Early on in this function is the line:

$url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@()]|i', '', $url);

Just change this to:

$url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@()$]|i', '', $url);

i.e. add the $ sign just before the closing square bracket - the characters enclosed in this set of brackets will not be replaced in URLs.

This may have other implications I haven't discovered yet, so I would advise this as a temporary fix which should be removed when your site goes live.

If you discover any other issues or solutions with using Wordpress and Plesk's SitePreview, please leave a comment below.

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