Title: PHP Mail method sent mail twice
Last modified: October 29, 2021

---

# PHP Mail method sent mail twice

 *  [ahmedsana1998](https://wordpress.org/support/users/ahmedsana1998/)
 * (@ahmedsana1998)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/php-mail-method-sent-mail-twice/)
 * I’m using the PHP mail method with my form,
 * but when I click on submit, the email is sent twice …
 * I don’t why this happened
 * my code works fine in the localhost without duplicating the email … so I think
   the problem is not in my code
 * **Note**: I’m using **PHPcode Snippet** plugin in the WordPress to add the PHP
   code in my WordPress page

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [yogeshyadav20](https://wordpress.org/support/users/yogeshyadav20/)
 * (@yogeshyadav20)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/php-mail-method-sent-mail-twice/#post-15017516)
 * Hi [@ahmedsana1998](https://wordpress.org/support/users/ahmedsana1998/)
 * Add condition like this,
 *     ```
       if(mail($to, $subject, $message, $headers)){
                       header('Location: contactez-nous.php?CaptchaPass');
   
           }else{
               echo "mail could not be sent";
           }
       ```
   
 * Hope this will be helpful for you, and let me know if it’s work your
 * Thanks
 *  Thread Starter [ahmedsana1998](https://wordpress.org/support/users/ahmedsana1998/)
 * (@ahmedsana1998)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/php-mail-method-sent-mail-twice/#post-15018593)
 * Hi,
 * Thank you for your response,
 * unfortunately, it didn’t work
 * this is my code for sending mail
 *     ```
           if (mail($mailto, $subject_from_web, $message_fromCustomer, $header_ToWebOwner)&& mail($from, $subject_confirmation, $message_AutoReplay_ToClient, $headers_ToClient)) {
       			 header('Location: contactez-nous.php?CaptchaPass');
               echo '<script type="text/javascript">successFunction("Message was sent successfully, check your emails!");</script>';
           } else {
               echo '<script type="text/javascript">failedFunction("Mail was not sent, Try again!.");</script>';
           }
       ```
   
 *  Thread Starter [ahmedsana1998](https://wordpress.org/support/users/ahmedsana1998/)
 * (@ahmedsana1998)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/php-mail-method-sent-mail-twice/#post-15022636)
 * Hello again,
 * There are Any Updates?

Viewing 3 replies - 1 through 3 (of 3 total)

 The topic ‘PHP Mail method sent mail twice’ is closed to new replies.

## Tags

 * [php mail](https://wordpress.org/support/topic-tag/php-mail/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [ahmedsana1998](https://wordpress.org/support/users/ahmedsana1998/)
 * Last activity: [4 years, 11 months ago](https://wordpress.org/support/topic/php-mail-method-sent-mail-twice/#post-15022636)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
