Php Guestbook email trouble

Could anyone take a quick look at this .php doc and let me know why I am not getting the email notification when an entry is posted? I’m tearing my hair out trying to figure it out!!!
Thanks!

<?
    if (!isset($name) || !isset($email) || !isset($message) || empty($name) || empty($email) || empty($message)) {
         print "&result=Fail";
         print "&errorMsg=" . urlencode("Input required for all fields.");
         exit;
    }

    $email = strtolower($email);

    addentry($name, $email, $message);

function addentry($name, $email, $message) {

    $posted = strftime("%D %I:%M %p");

    $message = stripslashes($message);

    $file = fopen('entry.txt', 'a+');

    if (!$file) {
         print "&result=Fail";
         print "&errorMsg=" . urlencode("Could not open entry.txt file. Change CHMOD levels to 766.");
         exit;
    }

    fputs($file, "<font color=\"#000000\">Name:</font> $name
<font color=\"#000000\">Email:</font> <font color=\"#CCCCCC\"><u><A href=\"mailto:$email\">$email</A></u></font><br>
<font color=\"#000000\">Posted:</font> $posted
<font color=\"#000000\">Message:</font> $message

");
    fclose($file);

    // Send admin an email when new entry occurs
    // mailAdmin($name, $email);
}

function mailAdmin($name, $email) {
    $mailTo = "Michael Mancilla <[email protected]>";
    $mailFrom = "From: Guestbook <[email protected]>";
    $mailSubject = "New Guestbook Entry";
    $mailBody = "$name ($email) has just posted in your guestbook

View it at http://www.hivandrelationships.com";
    mail($mailTo, $mailSubject, $mailBody, $mailFrom);
}

print "&result=okay";
exit;

?>

you’ve commented out the line of code that calls your mail function! :stuck_out_tongue:

change this:


// mailAdmin($name, $email);

to


mailAdmin($name, $email);

let me know how you get on :wink:

I owe you my first born …
Thanks ever so much for helping me out, I sincerely appreciate it!
Merci,
Flobair

One last question about this code: as it is, if you don’t insert an email address, it requests one. What can I do to make that email input optional and not mandatory?
Thanks!!

Change the start of the php from this:


<?
    if (!isset($name) || !isset($email) || !isset($message) || empty($name) || empty($email) || empty($message)) {
         print "&result=Fail";
         print "&errorMsg=" . urlencode("Input required for all fields.");
         exit;
    }

to something like this:


<?
    if (!isset($email) || empty($email)) {
         $email = "email not supplied";
    }
    if (!isset($name) || !isset($message) || empty($name) || empty($message)) {
         print "&result=Fail";
         print "&errorMsg=" . urlencode("Input required for all fields.");
         exit;
    }

this’ll replace any undefined email addresses with ‘email not supplied’, hope this helps :stuck_out_tongue:

oy … worked only half way: although it did not give me an error when I omitted the email, it no longer sends me an email. And now, even after having put back the original code, it still doesn’t work …
Here it is, if you want to see it:
http://www.hivandrelationships.com/phpGuestBook/guestbook.html

could you post how your php now looks please

sure …

<? 
____ if_(!isset($name)_||_!isset($email)_||_!isset($message)_||_empty($name)_||_empty($email)_||_empty($message))_{ 
_________print_ "&result=Fail" ;
_________print_ "&errorMsg=". urlencode ("Input required for all fields." ); 
_________exit; 
____} 

    $email = strtolower($email);

    addentry($name, $email, $message);

function addentry($name, $email, $message) {

    $posted = strftime("%D %I:%M %p");

    $message = stripslashes($message);

    $file = fopen('entry.txt', 'a+');

    if (!$file) {
         print "&result=Fail";
         print "&errorMsg=" . urlencode("Could not open entry.txt file. Change CHMOD levels to 766.");
         exit;
    }

    fputs($file, "<font color=\"#000000\">Name:</font> $name
<font color=\"#000000\">Email:</font> <font color=\"#CCCCCC\"><u><A href=\"mailto:$email\">$email</A></u></font><br>
<font color=\"#000000\">Posted:</font> $posted
<font color=\"#000000\">Message:</font> $message

");
    fclose($file);

    // Send admin an email when new entry occurs
    mailAdmin($name, $email);
}

function mailAdmin($name, $email) {
    $mailTo = "Michael Mancilla <[email protected]>";
    $mailFrom = "From: Guestbook <[email protected]>";
    $mailSubject = "New Guestbook Entry";
    $mailBody = "$name ($email) has just posted in your guestbook

View it at http://www.hivandrelationships.com/phpGuestBook/guestbook.html";
    mail($mailTo, $mailSubject, $mailBody, $mailFrom);
}

print "&result=okay";
exit;

?>

ok, I just cleaned that up and it works now … so back to square one …

you’ve got the script working again, but you still need help making the email to be optional?

Yes … and now that I think about it, what I originally did was simply copy/paste your code from this page onto my .php doc. Maybe I should simply type it all out by hand?
I’ll duplicate/save my original php this time and try again.
Whatever the case,thanks ever so much for taking the time to help me out; I truly appreciate it.

hey thats no problem, you’re welcome :wink: let me know how you get on