PDA

View Full Version : send email onload



kimberlyhello
04-12-2007, 09:07 PM
Is there a way to send out an email to a certain address, every time a particular page has loaded?

I searched for the answer, and can't seem to find anything about it.

Maybe it's not possible.

If it is possible, can someone tell me if I can do it with javascript.

Thanks,
Kim

thetestingsite
04-12-2007, 11:01 PM
You could use AJAX (a form of javascript) to call a PHP (or any other server-side script) that would then send the email. You wouldn't be able to do it with just javascript though. Then again, if you go that route, you may want to just use the server side language directly.

//EDIT: If you would like the basics of sending email using PHP and a mail server, simply use the following:



<?php
$to = "me@mydomain.com"; //the address the email is being sent to
$subject = "This is the subject"; //the subject of the message
$msg = "This is the message"; //the message of the email

mail($to, $subject, $msg, 'From: PHP Script <noreply@domain.com>'); //send the email.
?>


Either way, hope this helps.

mburt
04-13-2007, 12:29 AM
I think the OP was looking for a client-side solution.
There was a post a while back that John wrote a function for, using the mailto protocol.

If the OP can use PHP and has an SMTP server, that will work fine.

thetestingsite
04-13-2007, 12:47 AM
Well, if you were to use the mailto function then that would just open the default mail browser on the user's computer. They would then have to hit the send button in that program to send the email. If the OP wants a somewhat "automatic response" from site (that sends the email), then PHP or some other server-side language with and SMTP server would be the best bet.

kimberlyhello
04-13-2007, 06:39 AM
Yes, I am looking for something automatic.

When a person loads a particular page on my website, I want a script to automatically send me an email.

so I understand how to use a php script to send the email. The problem I'm having now is how to call the php script using javascript.

I know how to do this with a submit button, but I want it to run the php when a page loads. I don't want the person to have to click anything.

codeexploiter
04-13-2007, 06:54 AM
If you are looking for sending a mail while the visitor visits a particular page only using client-side JavaScript (not Ajax) it may not be possible. As thetestingsite stated using Ajax you might be able to do so.

djr33
04-13-2007, 07:36 AM
Do it server-side. The end.
Ajax requires javascript supported and enabled, and STILL requires the PHP script anyway.
Really.... no point in trying to go around it.

Yamthief
04-22-2008, 01:42 PM
so I understand how to use a php script to send the email. The problem I'm having now is how to call the php script using javascript.

Don't put any javascript in the page, you don't need to. just put the php in anywhere in the page and change the file extension of the page from ".html" to ".php". Easy ;)