Cable Forum

Cable Forum (https://www.cableforum.uk/board/index.php)
-   Internet Discussion (https://www.cableforum.uk/board/forumdisplay.php?f=25)
-   -   Automatic mail on PHP web page? (https://www.cableforum.uk/board/showthread.php?t=33651751)

Walford 23-06-2009 15:10

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?

funkyCable 26-06-2009 12:59

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.

Keyz333 26-06-2009 13:48

Re: Automatic mail on PHP web page?
 
Do you need the email to say WHO visited the page?
Or just that someone has?

Walford 26-06-2009 14:03

Re: Automatic mail on PHP web page?
 
Quote:

Originally Posted by Keyz333 (Post 34821677)
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?

Keyz333 26-06-2009 14:21

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. ;)

Cobbydaler 26-06-2009 14:27

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

Keyz333 26-06-2009 14:32

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

Walford 26-06-2009 15:40

Re: Automatic mail on PHP web page?
 
Quote:

Originally Posted by Cobbydaler (Post 34821704)
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 :-)

Graham M 26-06-2009 15:41

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 :)

Keyz333 26-06-2009 22:29

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


Graham M 26-06-2009 23:05

Re: Automatic mail on PHP web page?
 
Yeah sorry I couldve done that been busy lol

Keyz333 27-06-2009 00:25

Re: Automatic mail on PHP web page?
 
Haha, Thought I'd be helpful ;)


All times are GMT. The time now is 06:47.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum