0
$result = mysql_query("SELECT * FROM my_table ORDER BY company_name");

echo "<center><table border='1px' style='font-size: 12px;'>
<center><tr>
<th>Contact Email</th>
</tr></center>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['contact_email'] . "</td>";
  echo "</tr>";
  }
echo "</table></center>";

I need for the email addresses to be printed out as links so that users can just click on the email address to start an email. Is this possible?

  • [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – tereško Feb 14 '13 at 23:15

5 Answers5

2

you can do this by

echo  "<td><a href='mailto:".$row['contact_email']."'>".$row['contact_email'] ."</a></td>";

Note

  1. The entire ext/mysql PHP extension, which provides all functions named with the prefix mysql_, is officially deprecated as of PHP v5.5.0 and will be removed in the future. So use either PDO or MySQLi

Good read

  1. The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead
  2. PDO Tutorial for MySQL Developers
  3. Pdo Tutorial For Beginners
Community
  • 1
  • 1
NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143
2

Nothing magical about it...

echo <<< EOL
<td><a href="mailto:{$row['contact_email']}">{$row['contact_email']}</a></td>

EOL;
Marc B
  • 356,200
  • 43
  • 426
  • 500
1

Just do:

echo '<td><a href="mailto:' . $row['contact_email'] . '">' . $row['contact_email'] . '</a></td>';
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Develoger
  • 3,950
  • 2
  • 24
  • 38
1

This is an email link:

<a href="mailto:someone@example.com?Subject=Hello%20again">
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
elrado
  • 4,960
  • 1
  • 17
  • 15
1

That would be something like:

echo "<td><a href='mailto:" . htmlspecialchars($row['contact_email']) . "'>" . htmlspecialchars($row['contact_email']) . "</a></td>";
jeroen
  • 91,079
  • 21
  • 114
  • 132