Web Hosting Talk







View Full Version : E-Mail This page


thefunkysoulone
08-15-2005, 04:36 AM
Hi,
How would i go about adding a link that would send the URL from the current page to a an email address. I was lookng at the 'mailto' command bu that would need to know beforehand what email address i would be using and would be fixed.
Is there a way i could set it up so that it would ask for the address that i wanted to send it to?

sorry if that is a bit hard to understand. any help would be appreciated

cheers

Graeme_H
08-15-2005, 04:39 PM
You could do it with PHP pretty easily.

On the page where you want the user to be able to type in an email address you'd need something like this:


<form method="post" action="page2.php">
<input type="text" name="sendto">
<input type="submit">
</form>


Then on the next page (which would have to be called page2.php if that's what you entered for the action parameter):


<?
$message = "Message goes here";
$subject = "Subject goes here";
mail($_POST['sendto'], $subject, $message);

echo "Email has been sent";
?>


Basically what you'd get with this is a text box where the user can enter an email address, then click submit and an email will automatically be sent to that person. But of course, you'd need php with mail function enabled to do this.

lbwd
08-15-2005, 08:26 PM
That is Cool :)

thefunkysoulone
08-16-2005, 07:05 AM
Cheers for that, but how and what is enabling mail function?

sorry for sounding like a complete idiot.

AstarothT
08-16-2005, 08:13 AM
PHP is a server side scripting "language". When a server is setup to run PHP the administrator can decide to disable certain features - like the ability to send emails.

I am not a javascript/ HTML expert but I dont know how to do what you want without using some form of server side scripting (CGI, ASP, PHP etc). As Graeme_H demonstrated, to do it would be simple but you need to check with the company hosting your site which (if any) server side scripting they allow

vito
08-16-2005, 08:48 AM
If you prefer Javascript, do the following.

Add this to the <head>:
<script language="javascript">
function mailpage()
{
mail_str = "mailto:?subject=Check out the " + document.title;
mail_str += "&body=I thought you might be interested in the " + document.title;
mail_str += ". You can view it at, " + location.href;
location.href = mail_str;
}
</script>
(You can edit all the text in bold)

Then add the following to the <body> of your page:

<a href="javascript:mailpage()">Click here</a> to
email this page to a friend.

Vito

lbwd
08-16-2005, 12:07 PM
hotscripts > search "tell a friend"

regernatez
08-16-2005, 08:42 PM
if it's like lbwd is saying "tell a friend", you can download a script like this easily, google for tell a friend php script.

Graeme_H
08-16-2005, 09:56 PM
Before you search for a script, you might wanna check with your host to see which, if any server side languages are available to you, like AstarothT said.