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

<?php echo $row_master_view['email']; ?>

Thanks in advance.

4
Contributors
8
Replies
12
Views
7 Years
Discussion Span
Last Post by meko22
0

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.

0

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.

-1
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>

Now you need the send_mail.php to send the actual mail

-1

Now save this as send_mail.php-

<?
$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";}

?>
1

Why not let the browser handle it:

<?php 
  echo '<a href="mailto:' . $row_master_view['email'] . '">' . $row_master_view['email'] . '</a>';
?>
-1

yes, its cool too, but the process by ajax will be done in the backend.
page won't refresh while sending the mail.

1

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.

0

Why not let the browser handle it:

<?php 
  echo '<a href="mailto:' . $row_master_view['email'] . '">' . $row_master_view['email'] . '</a>';
?>

Exactly what I was after. Thankyou very much!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.