mail function sends email twice

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gauntletxg
Forum Newbie
Posts: 2
Joined: Thu Mar 13, 2008 3:29 pm

mail function sends email twice

Post by gauntletxg »

i'm new to php, and this is my first real script. it allows users to upload an image, and then it emails me telling me that something has been uploaded.

here's the part of my script that deals with email (with a fake address and website):

Code: Select all

// Setting up the email
$pfw_subject = "New file uploaded to server";
$pfw_email_to = "user@address.com";
$pfw_message = "A new picture has been uploaded to the gallery. In order for it to appear, you must approve it first:\n"
. "Link: http://www.awebsite.org/content/$newname\n";
mail($pfw_email_to, $pfw_subject ,$pfw_message) ;
?>
$newname is defined in the upload part of the script:

Code: Select all

// Unique name
$image_name=time().'.'.$extension;
 
// Store in gallery folder
$newname="gallery/".$image_name;
everything works fine, except i get one email with a link to just the folder (http://www.awebsite.org/content/) and a second email with the full link (http://www.awebsite.org/content/gallery/image.jpg)

any idea as to what's going wrong? i have a feeling it's a syntax error or something. thanks!
kryles
Forum Contributor
Posts: 114
Joined: Fri Feb 01, 2008 7:52 am

Re: mail function sends email twice

Post by kryles »

is the mail part in any kind of loop?
gauntletxg
Forum Newbie
Posts: 2
Joined: Thu Mar 13, 2008 3:29 pm

Re: mail function sends email twice

Post by gauntletxg »

nope, that's everything.

the reason i think it's syntax is that i orignally had this code:

Code: Select all

 
. "Link: $newname\n";
 
and everything worked great. but when i added in the site url so i can click on the link directly from my inbox, that's when i started getting emails twice.
zornfett
Forum Newbie
Posts: 1
Joined: Mon Apr 14, 2008 2:01 pm

Re: mail function sends email twice

Post by zornfett »

hello, I was actually looking for a solution like this; is it up? can you share it?
Thanks!
kryles
Forum Contributor
Posts: 114
Joined: Fri Feb 01, 2008 7:52 am

Re: mail function sends email twice

Post by kryles »

take off the \n at the end of "Link: $newname\n"; and see what happens
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: mail function sends email twice

Post by Chris Corbyn »

Sounds more like $newname comes from a form via $_POST and you're loading the page once without posting to it (i.e. the missing $newname) then you're posting to it which sends it correctly.
Post Reply