944,014 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 2886
  • PHP RSS
Nov 4th, 2009
0

PHP echo email address as mailto

Expand Post »
Hi,
I'm sure this is very simple but am unable to find out how.
How do I display an email address as a mailto link like in HTML? I have records displayed from a mysql db but would like to display a member email address that acts as a mailto link. Below displays the code that echos the value but of course I would like the value (email address) to function as a mailto link in HTML
php Syntax (Toggle Plain Text)
  1. <?php echo $row_master_view['email']; ?>
Thanks in advance.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
meko22 is offline Offline
4 posts
since Nov 2009
Nov 4th, 2009
0
Re: PHP echo email address as mailto
I assume you want to mail on click of this link, if so, execute the php script to send a mail using ajax on click of this link.
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009
Nov 4th, 2009
0
Re: PHP echo email address as mailto
Click to Expand / Collapse  Quote originally posted by network18 ...
I assume you want to mail on click of this link, if so, execute the php script to send a mail using ajax on click of this link.
That's right. I want to open the users email client to send mail, as the mailto function does in HTML. Could you modify the code or provide an example of how this is done? Thanks for your quick response.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
meko22 is offline Offline
4 posts
since Nov 2009
Nov 4th, 2009
-1
Re: PHP echo email address as mailto
PHP Syntax (Toggle Plain Text)
  1. var req = createXMLHttpRequest();
  2.  
  3. function createXMLHttpRequest() {
  4. var ua;
  5. if(window.XMLHttpRequest) {
  6. try {
  7. ua = new XMLHttpRequest();
  8. } catch(e) {
  9. ua = false;
  10. }
  11. } else if(window.ActiveXObject) {
  12. try {
  13. ua = new ActiveXObject("Microsoft.XMLHTTP");
  14. } catch(e) {
  15. ua = false;
  16. }
  17. }
  18. return ua;
  19. }
  20.  
  21. function sendRequest()
  22. {
  23. //var rnd982g = Math.random();
  24. // var str = "";
  25. var url= 'send_mail.php';
  26. if(document.getElementById('txtName') !='' && document.getElementById('txtName') != null)
  27. {
  28. url +="?name="+document.getElementById('txtName').value;
  29. }
  30. if(document.getElementById('txtMail') !='' && document.getElementById('txtMail') != null)
  31. {
  32. url +="&id="+document.getElementById('txtName').value;
  33. }else
  34. {
  35. alert("enter email address");
  36. return false;
  37. }
  38. if(document.getElementById('txtBody')!='' && document.getElementById('txtBody')!=null)
  39. {
  40. url+="&body="+urldocument.getElementById('txtBody').value;
  41. }else
  42. {
  43. alert("email body is empty");
  44. return false;
  45. }
  46.  
  47. req.open('GET', url);
  48. req.onreadystatechange = handleResponse;
  49. req.send(null);
  50. return false;
  51. }
  52.  
  53. function handleResponse() {
  54. if(req.readyState == 4){
  55. var response = req.responseText;
  56. document.getElementById("results").innerHTML = response;
  57. }
  58. }
  59. </script>
  60. <? ?>
  61. <html>
  62. <head></head>
  63. <body>
  64. <form name="frm" id="frm" method="post" target="">
  65. <table>
  66. <tr><td>Name</td><td><input type="text" name="txtName" id="txtName" /></td></tr>
  67. <tr><td>Email Address</td><td><input type="text" name="txtMail" id="txtMail" /></td></tr>
  68. <tr><td>Body</td><td><textarea name="txtBody" id="txtBody" ></textarea></td></tr>
  69. <tr><td><input type="submit" value="Send Mail" onclick="sendRequest();" /></td></tr>
  70. </form>
  71. </body>
  72. </html>
Now you need the send_mail.php to send the actual mail
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009
Nov 4th, 2009
-1
Re: PHP echo email address as mailto
Now save this as send_mail.php-
PHP Syntax (Toggle Plain Text)
  1. <?
  2. $name = $_GET['name'];
  3. $email_id = $_GET['id'];
  4. $body = $_GET['body'];
  5. $subject = "This is the subject";
  6.  
  7. if(mail($email_id,$subject,$body))
  8. {
  9. echo "Done";
  10. }
  11. else{ echo "Failed";}
  12.  
  13. ?>
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009
Nov 4th, 2009
1
Re: PHP echo email address as mailto
Why not let the browser handle it:

php Syntax (Toggle Plain Text)
  1. <?php
  2. echo '<a href="mailto:' . $row_master_view['email'] . '">' . $row_master_view['email'] . '</a>';
  3. ?>
Sponsor
Featured Poster
Reputation Points: 550
Solved Threads: 731
Bite my shiny metal ass!
pritaeas is offline Offline
4,182 posts
since Jul 2006
Nov 4th, 2009
-1
Re: PHP echo email address as mailto
yes, its cool too, but the process by ajax will be done in the backend.
page won't refresh while sending the mail.
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009
Nov 4th, 2009
1
Re: PHP echo email address as mailto
Click to Expand / Collapse  Quote originally posted by network18 ...
yes, its cool too, but the process by ajax will be done in the backend.
page won't refresh while sending the mail.
Reread the first post and the title.

The OP wants a mailto link, not a PHP mail() function.
Reputation Points: 96
Solved Threads: 124
Master Poster
Will Gresham is offline Offline
728 posts
since May 2008
Nov 5th, 2009
0
Re: PHP echo email address as mailto
Click to Expand / Collapse  Quote originally posted by pritaeas ...
Why not let the browser handle it:

php Syntax (Toggle Plain Text)
  1. <?php
  2. echo '<a href="mailto:' . $row_master_view['email'] . '">' . $row_master_view['email'] . '</a>';
  3. ?>
Exactly what I was after. Thankyou very much!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
meko22 is offline Offline
4 posts
since Nov 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: how ro grab discription from oteh website in php?
Next Thread in PHP Forum Timeline: session in php





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC