Email duplicity using PHP Mail()

Asked

Viewed 37 times

0

I need help, I don’t know where is the error to generate e-mail duplicity only for $to. Below is my code:

$mails = '[email protected]';
$Nome = 'Fulano';
$Email = '[email protected]';

        $to      = '[email protected]';
        $subject = 'teste';
        // To send HTML mail, the Content-type header must be set
        $headers  = 'MIME-Version: 1.1' . "\r\n";
        $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
        $message = 'mensagem minha mensagem';

        $headers .= 'From: '.$Nome.'<'.$Email.'>'. "\r\n";
        if ($mails != ''){
            $headers .= 'Cc: '.$mails.''. "\r\n";
        }
        $headers .= 'X-Mailer: PHP'."\r\n"; //mailer
        $headers .= 'X-Priority: 3'."\r\n"; //1 UrgentMessage, 3 Normal
        /*$headers .= 'Return-Path: '.$Email.''."\r\n"*/;
        $headers .= 'Reply-to: '.$Email.''."\r\n";
        mail($to, $subject, $message, $headers);

        echo "true";
        exit(); // coloquei pra ver se matava algum loop, mais não deu certo porque não tem loop nenhum.

Obs: I placed fake emails

  • Wilson, as the exit(); failed, tries to create a variable, and does a type check if(envia){mail($to, $subject, $message, $headers); envia = false;} p/ confirm that there really is no loop.

  • Is this mail function native or do you keep the code? If it’s your application’s code, you could put the relevant snippets in the question?

  • Update your question by stating the exact error your code shows.

  • The code I presented is trustworthy to what I am using, is not involved in any loop/loop, but as this occurring duplicity when receiving the email I put an Exit() so that it does not occur more than 1 time, but Exit() was neither in my starting code nor takes effect now. As for the error message it does not generate, it only duplicates the receipt of the email in the Webmail inbox.

  • 1

    Thank you all for your help. The email set up in the $To variable received a copy of all emails from the domain, so when sending a copy to another email it received a new copy of the email. Solution: I removed it from $To and it worked. If it’s possible colleagues can close/close this post. Thank you

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.