Page 1 of 1

mail function sends email twice

Posted: Thu Mar 13, 2008 3:38 pm
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!

Re: mail function sends email twice

Posted: Thu Mar 13, 2008 4:18 pm
by kryles
is the mail part in any kind of loop?

Re: mail function sends email twice

Posted: Thu Mar 13, 2008 4:31 pm
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.

Re: mail function sends email twice

Posted: Mon Apr 14, 2008 3:29 pm
by zornfett
hello, I was actually looking for a solution like this; is it up? can you share it?
Thanks!

Re: mail function sends email twice

Posted: Mon Apr 14, 2008 4:22 pm
by kryles
take off the \n at the end of "Link: $newname\n"; and see what happens

Re: mail function sends email twice

Posted: Mon Apr 14, 2008 5:42 pm
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.