Topic: PHP Mail() send 31 emails at a time

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

Re: PHP Mail() send 31 emails at a time

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.

Re: PHP Mail() send 31 emails at a time

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

Re: PHP Mail() send 31 emails at a time

That script should NOT send even 2 emails wink

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... big_smile

Re: PHP Mail() send 31 emails at a time

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.

Re: PHP Mail() send 31 emails at a time

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

Last edited by fazlionline (2009-10-26 00:29:23)

Re: PHP Mail() send 31 emails at a time

What does the code for the form look like? Do you have a field with a name of "email"?

Re: PHP Mail() send 31 emails at a time

http://www.fazlionline.com/karwan/contact.php

Re: PHP Mail() send 31 emails at a time

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([email you are sending to], [subject], [message], [headers]);