0
I got a problem, I made a script
to send multiple emails, the problem is that it only sends to the first result of the select
,and out of the loop
without sending to the missing ones, below is the code. If someone knows what it might be that 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");
}
}
pq vc define the constants within while? they are constants pq ... their value does not change ...
– rray
Really, but I took the counting from inside but it continues with the same problem, sends to the first and to the other not
– Jonathan Willian
Any error message appears? put this at the beginning,
ini_set('display_errors', true); error_reporting(E_ALL);
– rray
No mistakes, but I realized that he is doing the number of correct loops, so much so that more than one email arrives in the inbox, the first result, I do not know why the foreach is not bringing the other data
– Jonathan Willian