PHP echo email address as mailto

Thread Solved

Join Date: Nov 2009
Posts: 4
Reputation: meko22 is an unknown quantity at this point 
Solved Threads: 0
meko22 meko22 is offline Offline
Newbie Poster

PHP echo email address as mailto

 
0
  #1
Nov 4th, 2009
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
  1. <?php echo $row_master_view['email']; ?>
Thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 557
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
0
  #2
Nov 4th, 2009
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.
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 4
Reputation: meko22 is an unknown quantity at this point 
Solved Threads: 0
meko22 meko22 is offline Offline
Newbie Poster
 
0
  #3
Nov 4th, 2009
Originally Posted by network18 View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 557
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
-1
  #4
Nov 4th, 2009
  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
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 557
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
-1
  #5
Nov 4th, 2009
Now save this as send_mail.php-
  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. ?>
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 883
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 142
Sponsor
pritaeas's Avatar
pritaeas pritaeas is online now Online
Practically a Posting Shark
 
1
  #6
Nov 4th, 2009
Why not let the browser handle it:

  1. <?php
  2. echo '<a href="mailto:' . $row_master_view['email'] . '">' . $row_master_view['email'] . '</a>';
  3. ?>
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 557
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
-1
  #7
Nov 4th, 2009
yes, its cool too, but the process by ajax will be done in the backend.
page won't refresh while sending the mail.
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 525
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro
 
0
  #8
Nov 4th, 2009
Originally Posted by network18 View Post
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.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 4
Reputation: meko22 is an unknown quantity at this point 
Solved Threads: 0
meko22 meko22 is offline Offline
Newbie Poster
 
0
  #9
Nov 5th, 2009
Originally Posted by pritaeas View Post
Why not let the browser handle it:

  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!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 449 | Replies: 8
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC