htlm or java script code to send email

I would like to put embedded code in a web page so that if someone visited that page on our website it would send an email to a given address.  

I don't want to have any submit buttons or anything visible to the web page visitor.  I want it to happen behind the scene.
eckrothmusicAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dimmergeekCommented:
You cannot do this purely with HTML and/or JavaScript.
You will need a scripting language such as ASP.NET or PHP.
Here is some PHP code that you can run each time the page is called...

put this at the VERY TOP of your web page and re-name it as .php extension.

<?php
	// send e-mail on page load
	$page = $_SERVER['REQUEST_URI'];
	$fromadd = "mailfrom@domain.com";
	$to = "mailto@domain.com";
	$subject = "The web page " . $page . " has been visited";
	$mailText = "The web page " . $page . " has been visited";
	$mymail = "<html><body bgcolor='#FFFFFF'>" . $maillText . "</body></html>";
	$mymail = str_replace("\n.", "\n..", $mymail);
	$mymail = wordwrap($mymail, 70, "\r\n");

	// To send HTML mail, the Content-type header must be set
	$headers  = 'MIME-Version: 1.0' . "\r\n";
	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

	// Additional headers
	$headers .= "To: tomail@domain.com <tomail@domain.com>\r\n";
	$headers .= "From: frommail@domain.com <frommail@domain.com>\r\n";
	mail( $to, $subject, $mymail, $headers);
%>

Open in new window

0
dimmergeekCommented:
If you are loking to track visitors, there are better methods.  THe code above will do what you asked, but if someone visits the same page multiple times, you'll get multiple e-mails.
You're better off setting a cookie value of the vistor's IP address and writing the visit to a database.  Then on re-visits, you can check for the presence of the cookie value and determine whether to write to the db or not.
Maybe you don't want to counrt visits back to the same page by the same user within 1/2 hour or something like that.
0
eckrothmusicAuthor Commented:
ok.  this looks good!  

I am actually putting this on an error page so that I am notified if a user gets this page.

Question:  in your code where do I change the frommail and tomail to the actually email addresses?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

dimmergeekCommented:
CODE EDIT:

<?php
    // send e-mail on page load
    $page = $_SERVER['REQUEST_URI'];
    $fromadd = "from@domain.com";
    $to = "to@domain.com";
    $subject = "The web page " . $page . " has been visited";
    $mailText = "The web page " . $page . " has been visited";
    $mymail = "<html><body bgcolor='#FFFFFF'>" . $mailText . "</body></html>";
    $mymail = str_replace("\n.", "\n..", $mymail);
    $mymail = wordwrap($mymail, 70, "\r\n");

    // To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    // Additional headers
    $headers .= "To: to@domain.com <to@domain.com>\r\n";
    $headers .= "From: from@domain.com <from@domain.com>\r\n";
    mail( $to, $subject, $mymail, $headers);
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
eckrothmusicAuthor Commented:
thanks!
0
dimmergeekCommented:
You're welcome.
0
dimmergeekCommented:
Everywhere you see to@domain.com, substitute with your desired e-mail address.
Everywhere you see from@domain.com, substitute with your desired e-mail address.
0
dimmergeekCommented:
Does the error page accept input from the user from another page?
Are their variables you're expecting to be POSTed?
YOu can include those in the e-mail...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.