Automatic mail on PHP web page?
23-06-2009, 15:10
|
#1
|
|
Inactive
Join Date: Apr 2009
Location: Bristol
Services: 10MB Broadband from VM
Posts: 110
|
Automatic mail on PHP web page?
Is there anyway I can be emailed automatically when someone accesses a certain web page scripted in PHP? I don't know much PHP so I am looking really for someone to find my a code which does this?
|
|
|
26-06-2009, 12:59
|
#2
|
|
Inactive
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05
TV XL services
2MB BROADBRAND
UNLIMITED TALK PACKAGE
V+ Service (Since 18
Posts: 1,195
|
Re: Automatic mail on PHP web page?
should be fairly easy to send an email as soon as someone accesses a php page. You would need to write a session cookie to store a value to avoid getting multiple emails eg if a user refreshes/submits the page this would coarse the page to send another email which you may not want
Does your web pages use any authentication? Could I ask what you need this for? Do you have a it connected to a database such as mysql? If so you could record it there rather than emails.
|
|
|
26-06-2009, 13:48
|
#3
|
|
Inactive
Join Date: Oct 2007
Location: Fleet, Hampshire
Age: 35
Services: Cuckoo (BT) Broadband
Posts: 265
|
Re: Automatic mail on PHP web page?
Do you need the email to say WHO visited the page?
Or just that someone has?
|
|
|
26-06-2009, 14:03
|
#4
|
|
Inactive
Join Date: Apr 2009
Location: Bristol
Services: 10MB Broadband from VM
Posts: 110
|
Re: Automatic mail on PHP web page?
Quote:
Originally Posted by Keyz333
Do you need the email to say WHO visited the page?
Or just that someone has?
|
Just to say someone has visited and thats it.
Can anyone help?
|
|
|
26-06-2009, 14:21
|
#5
|
|
Inactive
Join Date: Oct 2007
Location: Fleet, Hampshire
Age: 35
Services: Cuckoo (BT) Broadband
Posts: 265
|
Re: Automatic mail on PHP web page?
Yeah, I'm sure I can find one for you, I'll send it over in a few minutes, when I find it
EDIT:
PHP Code:
<?php
$to = "Your@Emailhere.com";
$subject = "The Subject";
$body = "EG - Someone has Visited Your Website";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
If you add something like that into the PHP page, it should email you, everytime someone visits that certain PHP page.
Obviously if you fill it all in first.
|
|
|
26-06-2009, 14:27
|
#6
|
|
Inactive
Join Date: Apr 2006
Location: Manchester, UK
Services: ClearFibre Internet, Vodafone mobile Google Pixel 4
Posts: 9,699
|
Re: Automatic mail on PHP web page?
This is a simple php mail() function script
Code:
<?php
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
I guess you just stick it in as a script that runs when the page is visited. Not sure about the session cookie thing though...
|
|
|
26-06-2009, 14:32
|
#7
|
|
Inactive
Join Date: Oct 2007
Location: Fleet, Hampshire
Age: 35
Services: Cuckoo (BT) Broadband
Posts: 265
|
Re: Automatic mail on PHP web page?
It depends what kind of Page it is, if its one, where the same visitor would visit it multiple times, then you would be getting quite a few emails from the same user.
But if the user would only visit this page once, one of these 2 scripts would be fine
|
|
|
26-06-2009, 15:40
|
#8
|
|
Inactive
Join Date: Apr 2009
Location: Bristol
Services: 10MB Broadband from VM
Posts: 110
|
Re: Automatic mail on PHP web page?
Quote:
Originally Posted by Cobbydaler
This is a simple php mail() function script
Code:
<?php
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
I guess you just stick it in as a script that runs when the page is visited. Not sure about the session cookie thing though...
|
Thanks. I have used this one as it gives the option of a 'from' address.
Thanks for all your help though.
Jack :-)
|
|
|
26-06-2009, 15:41
|
#9
|
|
-
Join Date: Jul 2003
Location: Poole, Dorset
Age: 40
Services: FreeSat+
Tivo
V-Box
VM 60MBit
Posts: 13,365
|
Re: Automatic mail on PHP web page?
The previous script is actually better as it checks to see if the email was sent sucessfully rather than just assuming it was, you could easily merge the 2
|
|
|
26-06-2009, 22:29
|
#10
|
|
Inactive
Join Date: Oct 2007
Location: Fleet, Hampshire
Age: 35
Services: Cuckoo (BT) Broadband
Posts: 265
|
Re: Automatic mail on PHP web page?
Something like this should suit your needs, It has the From Function & checks to see if it sends or not.
PHP Code:
<?php
$to = "Your@Emailhere.com";
$subject = "The Subject";
$body = "EG - Someone has Visited Your Website";
$from = "someonelse@example.com";
$headers = "From: $from";
if (mail($to, $subject, $body, $headers)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
|
|
|
26-06-2009, 23:05
|
#11
|
|
-
Join Date: Jul 2003
Location: Poole, Dorset
Age: 40
Services: FreeSat+
Tivo
V-Box
VM 60MBit
Posts: 13,365
|
Re: Automatic mail on PHP web page?
Yeah sorry I couldve done that been busy lol
|
|
|
27-06-2009, 00:25
|
#12
|
|
Inactive
Join Date: Oct 2007
Location: Fleet, Hampshire
Age: 35
Services: Cuckoo (BT) Broadband
Posts: 265
|
Re: Automatic mail on PHP web page?
Haha, Thought I'd be helpful
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 11:17.
|