| | |
PHP echo email address as mailto
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 4
Reputation:
Solved Threads: 0
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
Thanks in advance.
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)
<?php echo $row_master_view['email']; ?>
•
•
Join Date: Sep 2009
Posts: 557
Reputation:
Solved Threads: 64
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
follow me on twitter
•
•
Join Date: Nov 2009
Posts: 4
Reputation:
Solved Threads: 0
0
#3 Nov 4th, 2009
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.
•
•
Join Date: Sep 2009
Posts: 557
Reputation:
Solved Threads: 64
-1
#4 Nov 4th, 2009
PHP Syntax (Toggle Plain Text)
var req = createXMLHttpRequest(); function createXMLHttpRequest() { var ua; if(window.XMLHttpRequest) { try { ua = new XMLHttpRequest(); } catch(e) { ua = false; } } else if(window.ActiveXObject) { try { ua = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { ua = false; } } return ua; } function sendRequest() { //var rnd982g = Math.random(); // var str = ""; var url= 'send_mail.php'; if(document.getElementById('txtName') !='' && document.getElementById('txtName') != null) { url +="?name="+document.getElementById('txtName').value; } if(document.getElementById('txtMail') !='' && document.getElementById('txtMail') != null) { url +="&id="+document.getElementById('txtName').value; }else { alert("enter email address"); return false; } if(document.getElementById('txtBody')!='' && document.getElementById('txtBody')!=null) { url+="&body="+urldocument.getElementById('txtBody').value; }else { alert("email body is empty"); return false; } req.open('GET', url); req.onreadystatechange = handleResponse; req.send(null); return false; } function handleResponse() { if(req.readyState == 4){ var response = req.responseText; document.getElementById("results").innerHTML = response; } } </script> <? ?> <html> <head></head> <body> <form name="frm" id="frm" method="post" target=""> <table> <tr><td>Name</td><td><input type="text" name="txtName" id="txtName" /></td></tr> <tr><td>Email Address</td><td><input type="text" name="txtMail" id="txtMail" /></td></tr> <tr><td>Body</td><td><textarea name="txtBody" id="txtBody" ></textarea></td></tr> <tr><td><input type="submit" value="Send Mail" onclick="sendRequest();" /></td></tr> </form> </body> </html>
"The discipline of writing something down is the first step towards making it happen."
follow me on twitter
follow me on twitter
•
•
Join Date: Sep 2009
Posts: 557
Reputation:
Solved Threads: 64
-1
#5 Nov 4th, 2009
Now save this as send_mail.php-
PHP Syntax (Toggle Plain Text)
<? $name = $_GET['name']; $email_id = $_GET['id']; $body = $_GET['body']; $subject = "This is the subject"; if(mail($email_id,$subject,$body)) { echo "Done"; } else{ echo "Failed";} ?>
"The discipline of writing something down is the first step towards making it happen."
follow me on twitter
follow me on twitter
1
#6 Nov 4th, 2009
Why not let the browser handle it:
php Syntax (Toggle Plain Text)
<?php echo '<a href="mailto:' . $row_master_view['email'] . '">' . $row_master_view['email'] . '</a>'; ?>
"If it is NOT source, it is NOT software."
-- NASA
-- NASA
•
•
Join Date: Sep 2009
Posts: 557
Reputation:
Solved Threads: 64
-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.
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
follow me on twitter
0
#8 Nov 4th, 2009
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.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
•
•
Join Date: Nov 2009
Posts: 4
Reputation:
Solved Threads: 0
0
#9 Nov 5th, 2009
•
•
•
•
Why not let the browser handle it:
php Syntax (Toggle Plain Text)
<?php echo '<a href="mailto:' . $row_master_view['email'] . '">' . $row_master_view['email'] . '</a>'; ?>
![]() |
Similar Threads
- How to echo html code in php echo (PHP)
- Email address showing as mailto link on webpage (PHP)
- Password Encryption (MySQL)
- PHP and Checkboxes in email (PHP)
- check if email address is correct without sending email? (PHP)
- Protecting email address from robots (PHP)
Other Threads in the PHP Forum
- Previous Thread: how ro grab discription from oteh website in php?
- Next Thread: session in php
Views: 449 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl customizableitems database date directory display download dynamic echo email error file files folder form format forms forum function functions google headmethod href htaccess html image include insert integration ip java javascript joomla limit link login loop mail malfunctioning menu methods mlm mod_rewrite multiple mysql oop parse parsing paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube





