Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted

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

Posted

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... :D

Posted

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.

Posted (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 by fazlionline

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...