Direct Mail Icon

Using PHP scripts in your messages

You can implement advanced mail-merge logic in your messages by using PHP scripting. PHP is a simple, powerful programming language that is used by many popular websites. You can use this language to write mini programs that are run when your message is sent. These mini programs can implement advanced mail-merge logic.

To learn more about PHP, see http://www.php.net.

To use PHP scripts in your messages:

Step 1

Choose Direct Mail > Preferences...

Step 2

Click the Messages icon.

Step 3

Check the "Execute PHP code in message body" check box.

Step 4

Type your PHP code directly into the body of the message, surrounding the code with <?php ... ?> tags.

The output of your PHP script will be merged back into message, replacing the original <?php ... ?> tags. To print output from your script, use PHP's print or echo functions.

Scripts are run once per recipient. As such, scripts should run quickly to avoid slowing down mail delivery. Scripts running longer than 30 seconds will be terminated.

Scripts can access address list data for the current recipient using the $_DIRECTMAIL[] PHP associative array variable. The keys of the array are identical to names of mail-merge tags. For example, <?php print $_DIRECTMAIL['first name']; ?> outputs the first name of the current recipient.

To help you debug your PHP scripts, you can view a log of errors encountered during script execution. Choose Window > PHP Log.

Here is an example of using PHP scripts to perform advanced mail-merge logic. In this case, we want to merge the full name of the recipient (as it appears in our address list) if we have it, and the phrase "Sir or Madam" if we don't have the full name in our address list.

The body of our message would be as follows:

Dear <?php if ( $_DIRECTMAIL['full name'] ) print $_DIRECTMAIL['full name']; else print 'Sir or Madam'; ?>,

You are cordially invited to a dinner party...

Related Topics

Using mail-merge tags

Previewing messages