CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Error in mail function

 



etheracide
journeyman

Jul 3, 2001, 10:03 AM

Post #1 of 6 (765 views)
Error in mail function Can't Post

I will explain this the best that I can, if you need more info, please let me know.

In my script I have a textfield named email. I set the value of email = $link. This is used to post the user's E-mail address into the page that the script generates. I then tried to set it up so that it would automatically send a thank you to the person who signed.

Here is the actual part for the auto thank you:

if ($link =~ /\@/) {
open (MAIL,"|$MAILPATH");
print MAIL "To: $link\n";
print MAIL "From: $MYEMAIL\n";
print MAIL "Subject: Thanks!\n";
print MAIL "Thank-you for signing my guestbook!\n
print MAIL "Please visit $TITLE again located at\n";
print MAIL "$SITE\n";
print MAIL "to see if anything new has been added\n";
print MAIL "since your last visit!\n\n";
print MAIL "--------------------------------------------\n";
print MAIL "Thanks,\n\n";
print MAIL "$MYNAME\n\n";
print MAIL "--------------------------------------------\n";
print MAIL "Powered by : Etheracidebook\n";
print MAIL "Copyright 2001 by Christopher-Michael Snyder\n";
print MAIL "http://wickedwebdesign.htmlplanet.com\n";
print MAIL "--------------------------------------------\n";
close (MAIL); }

(the format will be off on this code because I couldn't get it to fit into the box properly so this isn't the actual format of the code)

I tested the script and an E-mail was sent to the address associated with $link, but 'my' address "$MYEMAIL" also received the same E-mail. Each time that I test the script, it goes to the $link adress, but also to mine. After I straighten this out, I will add another mail function to have it send the user's values to "$MYEMAIL" to inform the administrator when someone signs their book, but i haven't put that in yet. I need to figure out why my address is receiving it as well. Probably too simple when I am looking for something too complex.

Is there something that I need to add to make sure that the $link in the mail inputs the latest value or something? I am stuck. Thank you for the time you spent reading this =0) As usual, i will make notice of the person who helps me on the site where I distribute my scripts =0) Thank you.



(This post was edited by etheracide on Jul 3, 2001, 9:20 AM)


etheracide
journeyman

Jul 3, 2001, 10:36 AM

Post #2 of 6 (760 views)
Re: Error in mail function [In reply to] Can't Post

as an addendum:

It now seems to be sending thank yous to every E-mail address as a new one is used. Everytime I sign the guestbook with a new E-mail address of mine, i get a thank you E-mail there as well as to all the old ones that i had previously signed with. So quite possibly it is reading ALL the $link values in the database.

Either way, it goes without saying. This bug is NOT good haha this would definitley flood the first couple of users' mailboxes =0)



mhx
Enthusiast / Moderator

Jul 3, 2001, 11:34 AM

Post #3 of 6 (758 views)
Re: Error in mail function [In reply to] Can't Post

It would be interesting how a value is assigned to $link, and which value is assigned to it. It would be of great help if you could attach the whole code.

-- Marcus



etheracide
journeyman

Jul 4, 2001, 1:03 AM

Post #4 of 6 (748 views)
Re: Error in mail function [In reply to] Can't Post

In the globals i have $entry set to a new entry.
$link = $entry->param("email");

This is where I set $link to the value that a user types into the E-mail field.

I have isolated the problem. What happens is that the cgi form prints to a guestbook file, and the second half of the CGI file is to create the new "HTML page" by taking each post off of the guestbook file and placing them on the page. The problem with the way that I am calling up the mail is that it is looking through the database and it actually adds the $link (E-mail) value in EVERY post in the guestbook file. Therefore everyone who has signed the guestbook will receive the new signer's thank you mail because their E-mail address is already in the guestbook file.

I need something that will limit the e-mail to only the LATEST added E-mail. Just the address that the new signer adds.

http://etheracide.hypermart.net/wickedweb/etheracidebookV2.txt

Here is the URL for my entire script. This version does not have the mail feature yet because that is the latest working version which i am offering. But in the post above I posted the actual script that I use to call up the mail. I entered it into the script directly after the part where I set the $link value and tell the new "HTML" page to post the mailto: in the posts.

I apologize for my poor technical reference as I am still in the process of learning to write my own CGIs. Thank you again for your help and let me know if you need anything else.





mhx
Enthusiast / Moderator

Jul 4, 2001, 2:11 AM

Post #5 of 6 (744 views)
Re: Error in mail function [In reply to] Can't Post

Hi,

why do you want to send the email in the foreach loop? As you stated in your code, the latest entry (to which you actually want to send a thankyou) if the first of the @entries. So if you move the mail code before the foreach loop and use

Code
$link = $entries[0]->param("email");

to get the address to send your thankyou note to, this should work quite well.
I haven't tried to understand the whole script, but as a general hint, you should try to put most of your code into subroutines and try to get rid of so many global variables. This will for sure make to code more readable and maintainable.
Hope this helps. If my proposal doesn't work, please tell and I'll have a closer look.

-- Marcus



etheracide
journeyman

Jul 5, 2001, 12:48 AM

Post #6 of 6 (731 views)
Re: Error in mail function [In reply to] Can't Post

And Marcus strikes again!! The idea you suggested worked! I did however have to put the @ in front of 'entries' because 'entries' is an array and not a scalar and therefore did not work when I attempted it. But I exchanged the $ for the @ and now it works perfectly!

As for all the globals that I use.... I use them because I am making this script as customizable as I can and this format seems to make it easier for everyone to customize to their needs because anything that they need to change is right up top. However, I may go with having the admin place all their values into a seperate file, but I wanted to get all the other features running before I tackle that =0)

I will be making notice of you on the site where I house my script when i update it to include the new version which will have the automatic thank you E-mail plus admin notification of new posts.

Thank you for your continued help.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives