Creating an email link only if there's an email address

3 posts by 2 authors in: Forums > CMS Builder
Last Post: January 23, 2020   (RSS)

By Deborah - January 23, 2020

Hi, CommonSenseDesign.

You believe you just need an "if" and "else" statements.

Give this a try:

<?php // if email address, show this
 if ($record['email_address']): ?>
<?php echo htmlencode($record['title']) ?> - <a href="mailto:<?php echo htmlencode($record['email_address']) ?>"><?php echo htmlencode($record['name']) ?></a>

<?php // if no email address, show this
 else: ?>
<?php echo htmlencode($record['title']) ?> - <?php echo htmlencode($record['name']) ?>
<?php endif ?>

That works perfectly, thank you! http://www.tcmhomes.com/