I'm trying to compose the body of an email using PHP evaluation within a rule. The rule is triggered when a new content is saved. Part of the email body is composed using HEREDOC and that works fine. This is the code I'm having trouble with:

//  Provide download link.
 if ($node->field_software_product_sku === "Some Product Name")
     echo "<a href=\"http://www.mywebsite.com/Some Product Name/some.exe\">Trial Version Download Link</a><br />";

The above code comes directly after the ending of the HEREDOC, but, before the closing '?>'. I anticipate that in the future, I will need to add more clauses to the 'if' statement, so, it's important that I get this to work.

I've tried several different incantations for coding the 'if'. I've tried using the token name enclosed in single quotes. And, I've tried using “==” instead of “===”. The only thing that seems to work consistently is commenting out the 'if'. Then, the “Trial Download Link” text does appear in the email. Unfortunately, the rule is to be used for multiple “skus”, so, I need to use the 'if'.

I'm hoping I've made a subtle mistake, or, overlooked something.

Can someone point me in the right direction?

Is there a way to debug the code to see why the 'if' may be failing?

1 Answer 1


If field_software_product_sku is text field you should test on value of the field something like:

if ($node->field_software_product_sku[LANGUAGE_NONE][0]['value'] === "Some Product Name"){
    echo "<a href=\"http://www.mywebsite.com/Some Product Name/some.exe\">Trial Version Download Link</a><br />";

other ways if it doesn't work, i suggest you to use Devel Module and dump the $node->field_software_product_sku using dpm function to see the value of the field:
dpm($node->field_software_product_sku) and then check on the value of the field.

  • Thanks. That worked. I knew I had missed something obvious.
    – rrirower
    Commented Feb 6, 2019 at 16:49
  • Great, marked as accepted, to help other.
    – berramou
    Commented Feb 7, 2019 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.