How do I get a form to send email to 2 recipients?

Asked

Viewed 1,768 times

0

I created a form where the user fills in some information and is sent an email to me with this information. Only at the moment it is only sending to 1 email.

Below follows the code:

  <?php
header('Content-Type: text/html; charset=utf-8');
header ("location: sucesso.html");
$radio=$_POST[radio];
$nome=$_POST[nome];
$num=$_POST[num];
$mes=$_POST[mes];
$aviso=$_POST[aviso];
$email=$_POST[email];
$assunto=$_POST[assunto];
$mensagem=$_POST[mensagem];

mail("[email protected]","Chegou um e-mail","
Campo 1: $radio
Campo 2: $num
Campo 3: $nome
Campo 4: $mes
Campo 7: $aviso 
");

echo "sua mensagem foi enviada com sucesso!";

?>

How to make him also send the emails to another recipient, only (hidden)?

In case he should send the emails to a common email, and another to a hidden one.

  • 1

    If it’s not a bulk shipment, prefer to use the mail() twice separately, because not all mailers respect the hidden copy. In some cases, there is the "leak" of headers, and this may reveal a receiver in the bcc.

1 answer

1

The hidden email you inform on header of the message, example:

// Vários 'para' separados por vírgula
$para  = '[email protected]' . ', ';
$para .= '[email protected]';

// Assunto
$assunto= 'Assunto';

// Mensagem
$mensagem = "Alguma mensagem";

// Headers
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Headers Adicionais
$headers .= 'To: Alguem <[email protected]>, Fulano <[email protected]>' . "\r\n";
$headers .= 'From: Mim <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n"; // Com cópia
$headers .= 'Bcc: [email protected]' . "\r\n"; // Cópia oculta

// Enviar
mail($para, $assunto, $menssagem, $headers);

More information: http://php.net/manual/en/function.mail.php

  • It would be nice to include the $para variable in the header as well, so the email is not considered spam

Browser other questions tagged

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