homepage Welcome to WebmasterWorld Guest from 54.167.173.250
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
mailto link in while loop php
garwil




msg:4350268
 9:42 am on Aug 11, 2011 (gmt 0)

Hi All...
I have a table generated in a while loop. One of the fields is an e-mail field and I am trying to create a mailto: link that when clicked will open an e-mail client (MS Outlook in my case)with the e-mail address in the TO: field.. I have tried everything I can think of and ended up with a little success with the below code. I found on the forums a way to get the mail link working by creating another variable called $mail ='<a href=mailto blah blah...</a> at the top of my table and using that variable which seemed to do the trick but presented me with a new problem :) which is that although the e-mail field displays the e-mail address in the table and formatted as a mailto: link and when clicked opens Outlook the actual e-maill address is not in the TO: field in Outlook...

Has anyone any idea as to what could be at fault here? Much appreciate any assistance

[/code]while($row = mysql_fetch_array($result)) {
$del_id = $row['id'];
$email= '<a href="mailto:"' . $row['email'] . '">' . $row['email'] . '</a>';
echo "<tr>";
echo "<td class=\"small\" align=\"center\">".$row['venuename']."</td>";
echo "<td class=\"small\" align=\"center\">".$row['venuetype']. "</td>";
echo "<td class=\"small\" align=\"center\">".$row['basis']. "</td>";
echo "<td class=\"small\" align=\"center\">".$row['province']. "</td>";
echo "<td class=\"small\" align=\"center\">".$row['city']. "</td>";
echo "<td class=\"small\" align=\"center\">".$row['region']. "</td>";
echo "<td class=\"small\" align=\"center\">".$row['tel']. "</td>";
echo "<td class=\"small\" align=\"center\">".$email. "</a></td>";
echo "<td align=\"center\"> <input type='checkbox' name='checkbox[]' id='checkbox[]' value='$del_id' </td>";
if ($row['published'] == '1')
echo "<td align=\"center\"><img src='images/yes.png'</td>";
else if ($row['published'] == '0')
echo "<td align=\"center\"><img src='images/no.png'</td>";
echo "<td><a href=\"javascript:;\" onClick=\"window.open('editprops.php?propref=$del_id', '_blank', 'width=900,height=700,toolbar=0,location=0,status=0,menubar=0,resizable=0,scrollbars=1');\">[edit]</a> </td>";
echo "<td><a href=\"javascript:;\" onClick=\"window.open('propindex.php?propref=$del_id', '_blank', 'width=900,height=700,toolbar=0,location=0,status=0,menubar=0,resizable=0,scrollbars=1');\">[manage]</a> </td>

</tr>";
echo "</tr>";
}
//echo "</table>";

if( mysql_num_rows($venues) > 0 ) echo " </table> ";[code]

 

omoutop




msg:4350287
 10:39 am on Aug 11, 2011 (gmt 0)

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


This seems correct format for your email. Have you checked for white spaces in the email address? Using trim() for example?

garwil




msg:4350411
 4:05 pm on Aug 11, 2011 (gmt 0)

Hi and thanks for the feedback... I have done a manual check on my e-mail addresses and they are prefect. AM not too sure how to use trim() but when I tried one of my previous attempts at fixing this the e-mail address appeared fine in Outlook however although displaying the e-mail adress perfectly it also displayed a whole lot of other gunk after the e-mail address, such as the </td> from that end of the field in question and this led me to reseach further for a solution.. bringing me to where I am now...

rocknbil




msg:4350412
 4:06 pm on Aug 11, 2011 (gmt 0)

Sounds like a config in your outlook, view the source and put it in a test file. What you have should work.

<OT but since you posted the code:>

Don't do this,

<a href=\"javascript:;\" onClick=\"window.open('propindex.php?propref=$del_id', '_blank', 'width=900,height=700,toolbar=0,location=0,status=0,menubar=0,resizable=0,scrollbars=1');\">[manage]</a>

Do this.

$unique_id = rand(5000,150000);

<a href=\"propindex.php?propref=$del_id\" onclick=\"window.open('propindex.php?propref=$del_id', '$unique_id', 'width=900,height=700,resizable,scrollbars'); return false;\">[manage]</a>

Why?

- Use unique window name: The window name is meant to be a unique identifier for the window. Using the same name for all windows opens this common scenario:
1. User clicks link. New window opens.
2. User clicks back in main window without closing pop up.
3. User clicks new link that has the same name, and it indeed opens the content and puts it in the open pop up, but the window is now behind the main window and they can't see it. Their summary: your site is broken and the links don't work.

A unique window name/id for all new windows fixes this.

- Link in the href: If Javascript is disabled, users can't access your content. Putting the real link in the href in combination with return false allows them to. The return false stops the main page from navigating to the link.

- Open parameters: =0,=1,=true,and =false are not necessary attributes. just include the attribute or not. It's also advisable to always include resizable as you never know what resolution your users will have.

garwil




msg:4350422
 4:27 pm on Aug 11, 2011 (gmt 0)

Hi all.... absolutley amazing how things work out... I been battling with this the whole day and left it alone for a bit...
Tried again and and hey presto... I got it to work with this code in case anyone else has the same isue..

echo "<td class=\"small\" align=\"center\"><a href=mailto:". $row['email'] . '>' . $row['email'] . "</a></td>";

Works like a charm and thanks so much for the input...

Matthew1980




msg:4350505
 6:57 pm on Aug 11, 2011 (gmt 0)

Hi there Garwill,

Excellent that you have sorted your issue out, but you're mixing your concatenations in your last post. It should read like this:-

echo "<td class=\"small\" align=\"center\"><a href=\"mailto:".$row['email']."\">".$row['email']."</a></td>";

this will now pass any mark up validation test as all of the assignments are within double quotes after the = if you see what I mean.

Typically if you start with echo ""; this means that when you are joining multiple things together, you need to keep to the convention that you opened with.

Hope that makes some sense ;p

Cheers,
MRb

garwil




msg:4350516
 7:17 pm on Aug 11, 2011 (gmt 0)

hey Matthew1980.. thanks so much for pointing that out to me... much obliged for the tip... I have now learnt one more thing today :)

Best regards

garwil




msg:4350523
 7:21 pm on Aug 11, 2011 (gmt 0)

rocknbil ... thanks for that input on my code... and here I thought it was all ok.. :) We live and learn thanks to all you out there that help..
Really appreciated....

rocknbil




msg:4350869
 5:04 pm on Aug 12, 2011 (gmt 0)

Well, 1000 apologies . . looks like we ALL missed this one and M led right to it. Go back to your original code:

'<a href="mailto:"' . $row['email'] . '">'

See that second " ? It will output

<a href="mailto:"oops@example.com">

And there was the original problem. changed to

'<a href="mailto:' . $row['email'] . '">'

it will be fine . . but you solved it another way, all good.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved