Search code examples
phphtmldatabasefetchmailto

Create an html mailto link from a database fetch


I'm having difficulty creating a mailto link from a user's inputted email address that's stored in a database (this is used for a comments section). I was hoping to create a new line with the email address printed with a mailto hyperlink. Instead, it doesn't print the email address, but instead turns all text below that line into a mailto hyperlink. See attached pictures for clarification.

echo "<h3><u>Latest Comments:</u></h3>";
while($fetch=mysql_fetch_array($query)) {
echo "<hr />";
echo "<p>".$fetch['comment']."<p>";     
echo "<header><h3>By: ".$fetch['comment_by']."</h3><br>"; 
echo "<a href='mailto:".$fetch['email'].">".$fetch['email']."</a></br>";
$sqldate = $fetch['datetime'];
$date=strtotime($sqldate);
echo "<span class='date'>On: " .date("m/d/Y, g:i A", $date)."</span></header></p>";

Notice, it fetches the correct email address, but doesn't create the hyperlink correctly using html. Also note this is all contained inside php tags.

link to photo showing problem


Solution

  • You're missing a quote:

    echo "<a href='mailto:".$fetch['email']."'>".$fetch['email']."</a></br>";
                                        -----^