fazlionline Posted October 22, 2009 Report Posted October 22, 2009 PHP Mail() send 31 emails at a time Hello everyone I have this script for my contact us page <?php $to = "123@yahoo.com"; $subject = $_REQUEST['subj'] ; $name = $_REQUEST['name'] ; $org = $_REQUEST['org'] ; $tele = $_REQUEST['tele'] ; $city = $_REQUEST['city'] ; $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $url = "Karwan - Contact Form"; $details = "\n URL - Form: $url\n Subject: $subject\n Name: $name\n Organization: $org\n Telephone: $tele\n City: $city\n From: $email \n Message: $message \n "; $headers = "From: $email"; $sent = mail($to, $url, $details, $headers, $message) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?> When a user fill the form and send it to me, I receive 31 messages in my inbox. Is there something wrong in my code? Regards Quote
falkencreative Posted October 22, 2009 Report Posted October 22, 2009 Is this consistent -- every user that uses the form sends 31 messages? Have you tried testing the form yourself? If so, do you receive 31 messages? I'm not seeing any reason why it should be sending it multiple times. That could happen if the user clicks "submit" multiple times, or refreshes the page multiple times. Quote
fazlionline Posted October 22, 2009 Author Report Posted October 22, 2009 Hi I have used the above script in two different websites I tested them now and one sent me 7 emails and the other sent 8 ones. I know that my internet is fast. The person from whom I received 31 emails, his internet connection is too slow. I also received 42 emails from the same from Quote
BeeDev Posted October 22, 2009 Report Posted October 22, 2009 That script should NOT send even 2 emails Why? Because there's no LOOP. Show us the whole page or the complete php code, theres nothing wrong with the code you posted above. Why would one send 7 e-mails and another send 8 e-mails? And 31 and 42 ...... this just doesn't make sense. So post your whole code or do it again from beginning... Quote
falkencreative Posted October 22, 2009 Report Posted October 22, 2009 One thing that I did want to point out -- though it may have nothing to do with your issue -- is that you are using the mail() function incorrectly. $sent = mail($to, $url, $details, $headers, $message) ; As far as I know, and based on the PHP Manual, mail() only includes 4 perimeters, not 5. The "$message" at the end is incorrect, and should be removed. You are already including the $message information within $details. (http://php.net/manual/en/function.mail.php) It might be worth checking to see if removing that helps solve the problem. Quote
fazlionline Posted October 25, 2009 Author Report Posted October 25, 2009 (edited) hi falkencreative I have changed my code to the following: <?php $to = "123@yahoo.com"; $subject = $_REQUEST['subj'] ; $name = $_REQUEST['name'] ; $org = $_REQUEST['org'] ; $tele = $_REQUEST['tele'] ; $city = $_REQUEST['city'] ; $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $url = "Karwan - Contact Form"; $details = "\n URL - Form: $url\n Subject: $subject\n Name: $name\n Organization: $org\n Telephone: $tele\n City: $city\n From: $email \n Message: $message \n "; $headers = "From: $email"; $sent = mail($to, $subject, $email, $message) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?> Now I only get one email But it is from anonymous@example.com and not from the email I have entered in the email fields in contact form Edited October 26, 2009 by fazlionline Quote
falkencreative Posted October 26, 2009 Report Posted October 26, 2009 What does the code for the form look like? Do you have a field with a name of "email"? Quote
fazlionline Posted October 26, 2009 Author Report Posted October 26, 2009 http://www.fazlionline.com/karwan/contact.php Quote
falkencreative Posted October 26, 2009 Report Posted October 26, 2009 I took a second look at your PHP code. You aren't including the headers, which is causing your problem, and you aren't fully following the PHP mail() format. It needs to be this: mail(, [subject], [message], [headers]); Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.