Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

How to stop duplicate emails?

Guest
Feb 17, 2011 Feb 17, 2011

I've been using the following bit of code to send out two emails when a user completes a 'contact us' form. The first email is sent to the website owner, and the second to the person who completes the form. The code has been edited to remove any real email addresses.

<?php
$to = "joe@blogs.co.uk";
$subject = "Website enquiry". $_POST['Name'];
$body  = "Name: ".$_POST['Name']."\n"."\n"."Location:  ".$_POST['Location']."\n"."\n"."Email Address:  ".$_POST['emailAddress']."\n"."\n"."Telephone Number:  ".$_POST['TelNo']."\n"."\n"."Comments: ".$_POST['Comments']."\n"."\n";
$headers = "From: ". $_POST['emailAddress'] ."\n";
mail($to,$subject,$body,$headers);
//?>

//<?php
$to = $_POST['emailAddress'];
$subject = "Thank you for contacting Joe";
$body = "Name: ".$_POST['Name']."\n"."\n"."Location:  ".$_POST['Location']."\n"."\n"."Email Address:  ".$_POST['emailAddress']."\n"."\n"."Telephone Number:  ".$_POST['TelNo']."\n"."\n"."Comments: ".$_POST['Comments']."\n"."\n";
$headers = "From: "."joe@blogs.co.uk"."\n";
mail($to,$subject,$body,$headers);
?>

However, it appears that the first email is sent twice. Also, the first time the email is sent it contains all the information passed from the form, and the second time it contains blanks.

I don't think  that the second email is sent twice.

It was suggested that I get rid of the closing php tag at the end of the first chunk of code and the opening one at the start of the second chunk. Hence it is commented out, but this has made no difference.

Any ideas gratelly received.

TOPICS
Server side applications
444
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 17, 2011 Feb 17, 2011

I can't answer your question, but I would not be sending the comments field back to the address in the form. What's to stop someone from using your form as a spam relay?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 18, 2011 Feb 18, 2011

Thanks, but could you expand on that a bit more? And is it just the comments field or all of them?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 18, 2011 Feb 18, 2011
LATEST

Any form that sends email to an address specified in the form could be used by spammers. Usually, if you validate and strip out url's so they can't post links, your form won't be hijacked often. But it will still happen. If you allow free form text to be sent, it will happen more often.

It's usually best to just send a hardcoded reply that their request was received. Otherwise, if you must send the comments, use a validation technique like CAPTCHA or similar.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines