Email notification after guestbook post to DB

software development

#1

i launched a new guestbook on my site today. i built it myself using PHP with entries stored in MySQL. what would be the simplest way to set it up so that i would receive an email notification whenever there’s a new entry?

thanks,
gabe


#2

[quote]i launched a new guestbook on my site today. i built it
myself using PHP with entries stored in MySQL. what would
be the simplest way to set it up so that i would receive
an email notification whenever there’s a new entry?

[/quote]

You can do this by calling the PHP “mail()” function in whatever function you use to insert the entries into the database, ie.

function InsertGBEntry($db, $val1, $val2, $val3) {

Insertion functions go here, etc. etc.

mail("you@yourdomain.com",“New Entry!”,“You have a new entry…”,NULL);
}

I didn’t check the above, but you get the idea. Here’s PHP.net’s documentation on the function:

http://www.php.net/manual/en/ref.mail.php

  • Jeff @ DreamHost
  • DH Discussion Forum Admin

#3

thanks, jeff! that works great! http://www.gabeanderson.com/guestbook/

but now i have a bigger problem: my inserts to the guestbook seemed to have stopped working since yesterday! i haven’t changed anything and i even commented out the mail function. i’m not getting any error or anything…it acts like it works, but nothing shows up. is something wrong with my database, perhaps?

thanks,
gabe


#4

from database manager re: my guestbook table:

Space usage : Type Usage
Data 1,456 Bytes
Index 2,048 Bytes
Overhead 372 Bytes
Effective 3,132 Bytes
Total 3,504 Bytes

Would that “overhead” line be the problem with why posts are suddenly not working?? i tried an insert from the command line and it works fine, but it won’t work from web form that worked fine yesterday.

thanks,
gabe


#5

now posting is suddenly working again! what’s going on here??

-gabe


#6

Hi gabe -

I’m pretty sure ‘overhead’ doesn’t have anything to do with it, in this case.

The best way to figure out if an insert isn’t working is to place the following line immediately after your query during debugging:

print mysql_error();

See if that prints out anything. Also, use a print statement to print out exactly the SQL query you’re using - if you type it in manually, it may work due to being subtly different in some way (ie. a passed variable not being present when it should be).

If all else fails … Post a code snippet. :>

  • Jeff @ DreamHost
  • DH Discussion Forum Admin