I have a problem, I made a script
to send multiple emails, the problem is that it only sends to the first result of select
, and already leaves loop
without sending to those that are missing, below the code. If anyone knows what that could be, it would help a lot:
<?php
include('../../config.php');
$evento = $_POST['evento'];
$assunto = $_POST['assunto'];
$msg = $_POST['corpo'];
$select_ins = "SELECT inscrito, evento FROM inscricoes WHERE status = 'Aprovado' AND evento =".$evento." ";
$insc = mysql_query($select_ins) or die(mysql_error());
while($ins = mysql_fetch_array($insc)){
$select_part = "SELECT nome, email, telefone FROM inscrito WHERE id=".$ins['inscrito'];
$parts = mysql_query($select_part) or die(mysql_error());
$part = mysql_fetch_array($parts);
$select_eve= "SELECT nome FROM eventos WHERE id=".$ins['evento'];
$eves = mysql_query($select_eve) or die(mysql_error());
$eve = mysql_fetch_array($eves);
$email = $part['email'];
$msg = str_replace('#nome', $part['nome'], $msg);
$msg = str_replace('#telefone', $part['telefone'], $msg);
$msg = str_replace('#evento', $eve['nome'], $msg);
date_default_timezone_set ('America/Sao_Paulo');
$corpo = "Email de teste para usuarios";
require ('../../../aws/aws-autoloader.php');
// Replace [email protected] with your "From" address.
// This address must be verified with Amazon SES.
define('SENDER', 'Eventos<[email protected]>');
// Replace [email protected] with a "To" address. If your account
// is still in the sandbox, this address must be verified.
define('RECIPIENT', $email);
// Replace us-west-2 with the AWS region you're using for Amazon SES.
define('REGION','us-east-1');
define('SUBJECT', $assunto); //Assunto digitado pelo Administrador
define('BODY', $corpo);
$client = Aws\Ses\SesClient::factory(array(
'version'=> 'latest',
'region' => REGION,
'credentials' => array(
'key' => 'AJSIDSAJIDSAJIDSAID',
'secret' => 'SOKAODSAKDOSADSA86SD6SA2',
)
));
$request = array();
$request['Source'] = SENDER;
$request['Destination']['ToAddresses'] = array(RECIPIENT);
$request['Message']['Subject']['Data'] = SUBJECT;
$request['Message']['Body']['Html']['Data'] = BODY;
try {
$result = $client->sendEmail($request);
$messageId = $result->get('MessageId');
echo("Emails enviados com sucesso! ");
} catch (Exception $e) {
echo("Erro ao enviar, confira se o email informado esta correto.");
echo($e->getMessage()."\n");
}
}