# Php Guestbook email trouble

**URL:** <https://forum.kirupa.com/t/php-guestbook-email-trouble/27010>\
**Category:** Uncategorized\
**Created:** [July 29, 2003, 10:46am UTC](https://forum.kirupa.com/t/php-guestbook-email-trouble/27010 "2003-07-29T10:46:15Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![flobair](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@flobair](https://forum.kirupa.com/u/flobair)\
**Post date:** [July 29, 2003, 10:46am UTC](https://forum.kirupa.com/t/php-guestbook-email-trouble/27010/1 "2003-07-29T10:46:15Z")

</div>

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!

```php
<?
    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 <gb@hivandrelationships.com>";
    $mailFrom = "From: Guestbook <gb@hivandrelationships.com>";
    $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;

?>

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 29, 2003, 2:12pm UTC](https://forum.kirupa.com/t/php-guestbook-email-trouble/27010/2 "2003-07-29T14:12:32Z")

</div>

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

change this:

```php

// mailAdmin($name, $email);

```

to

```php

mailAdmin($name, $email);

```

let me know how you get on 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 29, 2003, 2:20pm UTC](https://forum.kirupa.com/t/php-guestbook-email-trouble/27010/3 "2003-07-29T14:20:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 30, 2003, 8:15am UTC](https://forum.kirupa.com/t/php-guestbook-email-trouble/27010/4 "2003-07-30T08:15:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 30, 2003, 8:27am UTC](https://forum.kirupa.com/t/php-guestbook-email-trouble/27010/5 "2003-07-30T08:27:23Z")

</div>

Change the start of the php from this:

```php

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

```php

<?
    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 😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 30, 2003, 8:48am UTC](https://forum.kirupa.com/t/php-guestbook-email-trouble/27010/6 "2003-07-30T08:48:38Z")

</div>

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](http://www.hivandrelationships.com/phpGuestBook/guestbook.html)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 30, 2003, 8:52am UTC](https://forum.kirupa.com/t/php-guestbook-email-trouble/27010/7 "2003-07-30T08:52:43Z")

</div>

could you post how your php now looks please

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 30, 2003, 9:00am UTC](https://forum.kirupa.com/t/php-guestbook-email-trouble/27010/8 "2003-07-30T09:00:09Z")

</div>

sure …

```php
<? 
____ 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 <gb@hivandrelationships.com>";
    $mailFrom = "From: Guestbook <gb@hivandrelationships.com>";
    $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;

?>

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 30, 2003, 9:09am UTC](https://forum.kirupa.com/t/php-guestbook-email-trouble/27010/9 "2003-07-30T09:09:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 30, 2003, 9:38am UTC](https://forum.kirupa.com/t/php-guestbook-email-trouble/27010/10 "2003-07-30T09:38:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 30, 2003, 9:42am UTC](https://forum.kirupa.com/t/php-guestbook-email-trouble/27010/11 "2003-07-30T09:42:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 30, 2003, 9:43am UTC](https://forum.kirupa.com/t/php-guestbook-email-trouble/27010/12 "2003-07-30T09:43:47Z")

</div>

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