Created
October 28, 2023 22:04
-
-
Save vicctim/0fab67af86db4bb5366208e56f048b60 to your computer and use it in GitHub Desktop.
[html + php] envio whatsapp para varios numeros
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="process-form.php" method="post"> | |
<label for="nome">Nome:</label> | |
<input type="text" name="nome" id="nome"> | |
<label for="telefone">Telefone:</label> | |
<input type="text" name="telefone" id="telefone"> | |
<label for="email">E-mail:</label> | |
<input type="text" name="email" id="email"> | |
<label for="mensagem">Mensagem:</label> | |
<textarea name="mensagem" id="mensagem"></textarea> | |
<input type="submit" value="Enviar"> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Primeiro, verifique se o formulário foi enviado | |
if ($_SERVER["REQUEST_METHOD"] == "POST") { | |
// Extraia dados do formulário | |
$nome = $_POST["nome"]; | |
$telefone = $_POST["telefone"]; | |
$email = $_POST["email"]; | |
$mensagem = $_POST["mensagem"]; | |
// Crie a mensagem com base nos dados do formulário | |
$messageContent = "Formulário de .... " | |
. "\n\n" | |
. "*Nome*: " . $nome | |
. "\n*Telefone*: " . $telefone | |
. "\n*E-mail*: " . $email | |
. "\n*Mensagem*: " . $mensagem; | |
// Números de telefone para enviar a mensagem | |
$phoneNumbers = [ | |
"553433333333", | |
"553422222222", | |
"553411111111", | |
"553400000000" | |
]; | |
// Envie a mensagem para cada número | |
foreach ($phoneNumbers as $phone) { | |
sendMessageToAPI($phone, $messageContent); | |
} | |
} | |
// Função auxiliar para enviar uma mensagem via API | |
function sendMessageToAPI($phoneNumber, $message) { | |
$url = 'https://ALTERAR-URLAPI.com.br/send-message'; | |
$data = array('number' => $phoneNumber, 'message' => $message); | |
$options = array( | |
'http' => array( | |
'header' => "Content-type: application/x-www-form-urlencoded\r\n", | |
'method' => 'POST', | |
'content' => http_build_query($data), | |
'timeout' => 10 | |
) | |
); | |
$context = stream_context_create($options); | |
$result = file_get_contents($url, false, $context); | |
if ($result === FALSE) { | |
// Trate o erro, por exemplo, registre o erro ou notifique um administrador | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment