I'm having a problem when I want to send multi e-mails with PHP-Mailer inside a while.
I've the script that sends the email to 15 of 16 people when I'm doing to the SELECT in muy DB, and getting all the data with an array.
The code:
while($row=mysqli_fetch_array($rangocorreo)){
//Server settings
$mail->addAddress($row['correo'], $row['t_name']); // Add a recipient
$mail->Subject = 'Test';
$mail->Body = 'Esto es una mensaje de Prueba';
$mail->AltBody = '¡Test!';
$mail->ConfirmReadingTo = '';
//$mail->send();
if(!$mail->send()) {
//echo 'El mensaje no pudo enviarse. Motivo: ' . $mail->ErrorInfo;
}
$mail->ClearAddresses();
//usleep(500000);
}
I tried with different forms of the code, but finally only sends 15 instead of 16. (The e-mail is missing) Just a note, if I do the SELECT in the DB, gives me the 16 emails that I want, so I think the problem is not in the DB or in the query, I think is in this code.
Can you help me?
Kinds Regards.
Related
I'm having this problem while seeding my PGSQL Database:
Illuminate\Database\QueryException : SQLSTATE[22021]: Character not in repertoire: 7 ERROR: secuencia de bytes no válida para codificación «UTF8»: 0xe3 0x83 0xe2 (SQL: insert into "races" ("name", "public_name", "members", "updated_at", "created_at") values (harp��a, HarpÃa, 23, 2018-04-21 20:30:20, 2018-04-21 20:30:20) returning "id")
at C:\Sandbox\rpgforum\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Exception trace:
1 PDOException::("SQLSTATE[22021]: Character not in repertoire: 7 ERROR: secuencia de bytes no válida para codificación «UTF8»: 0xe3 0x83 0xe2")
C:\Sandbox\rpgforum\vendor\laravel\framework\src\Illuminate\Database\Connection.php:330
2 PDOStatement::execute()
C:\Sandbox\rpgforum\vendor\laravel\framework\src\Illuminate\Database\Connection.php:330
Please use the argument -v to see more details.
And this is my Seeder's code:
<?php
use Illuminate\Database\Seeder;
use App\Models\Race;
class RaceTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* #return void
*/
public function run()
{
$races = [
'Humano',
'Orco',
'Elfo',
'Harpía',
'Enano',
];
for ($i = 0; $i < count($races); $i++) {
$race_i = utf8_encode($races[$i]);
$race = Race::create([
'name' => strtolower($race_i),
'public_name' => $race_i,
'members' => mt_rand(10,30),
]);
} // for
}
}
My database configuration:
pgsql database
My config.database file config:
config.database file
Is there any solution for this problem? I can find the way to get rid of this problem...
EDIT:
I just noticed something weird. I got two records in my database:
database records
And both of them have symbols that gave me problem with the seeder. Maybe the problem is within the seeders logic? I'm doing the exact same thing I do the whole time with my Laravel/Postgresql projects so i can't find the reason why i can't seed words with accent mark but i can use a simple form to store that kind of information. Any ideas ?
If I run:
exec('myString') at [myserver]
my selection works correctly
If I do:
declare #mystring nvarchar(max) = 'myString'
exec(#mystring) at [myserver]
(Righe interessate: 2)
OLE DB provider "IBMDASQL" for linked server "myserver" returned message "SQL0104: Token '' non valido. Token validi: ( CL END GET SET CALL DROP FREE HOLD LOCK OPEN WITH ALTER BEGIN.
Causa . . . : È stato rilevato un errore di sintassi sul token ''. Il token '' non è valido. Un elenco parziale dei token validi è ( CL END GET SET CALL DROP FREE HOLD LOCK OPEN WITH ALTER BEGIN. Questo elenco presuppone che l'istruzione sia corretta fino al token. È possibile che l'errore sia precedente nell'istruzione, ,ma la sintassi dell'istruzione sembrava valida fino a questo punto. Correzione . . : Effettuare almeno una delle seguenti operazioni e ripetere: -- Verificare l'istruzione SQL nell'area del token ''. Correggere l'istruzione. L'errore potrebbe essere una virgola o apici mancanti, una parola scritta in modo scorretto oppure potrebbe essere relativo all'ordine delle clausole. -- Se il token di errore è , correggere l'istruzione SQL perché non termina con una clausola valida.".
(Righe interessate: 0)
Messaggio 7215, livello 17, stato 1, riga 308
Could not execute statement on remote server 'myserver'.
Here is the english version of SQL0104
Message ID . . . . . . . . . : SQL0104
Message file . . . . . . . . : QSQLMSG
Library . . . . . . . . . : QSYS
Message . . . . : Token &1 was not valid. Valid tokens: ( CL END GET SET CALL DROP FREE HOLD LOCK OPEN WITH ALTER BEGIN.
Cause . . . . . : A syntax error was detected at token ''. Token '' is not
a valid token. A partial list of valid tokens is ( CL END GET SET CALL DROP FREE HOLD LOCK OPEN WITH ALTER BEGIN. This list assumes that the statement is correct up to the token. The error may be earlier in
the statement, but the syntax of the statement appears to be valid up to
this point.
Recovery . . . : Do one or more of the following and try the request again:
-- Verify the SQL statement in the area of the token ''. Correct the
statement. The error could be a missing comma or quotation mark, it could
be a misspelled word, or it could be related to the order of clauses.
-- If the error token is , correct the SQL statement
because it does not end with a valid clause.
I'm working on a script to automatically configure Nodemanager, enroll a machine and starting de managed servers in it. What i currently have is (not exactly):
connect(...)
cd('/')
for m in cmo.getMachines():
nombre_machine=m.getName()
#Solo ejecutamos el NodeManager en el que estamos ejecutando el script.
if nombre_machine in HOST:
cd('/Machines/'+nombre_machine+'/NodeManager/'+nombre_machine)
machine=cmo
nm_srv_addrs[machine.getListenPort()] = machine.getListenAddress()
for nm_port, nm_addr in nm_srv_addrs.iteritems():
printInStyle('Iniciando Nodemanager, favor tener paciencia la primera vez.')
startNodeManager(verbose='false', NodeManagerHome=NM_HOME, ListenPort=str(nm_port), ListenAddress=nm_addr)
print 'Generando nodemanager.properties ',
while not os.path.exists(NM_PROP_FILE):
systime.sleep(10)
print '\b.',
sys.stdout.flush()
print 'Archivo creado!'
cd('/')
servidores = cmo.getServers()
for s in servidores:
nombre = s.getName()
if nombre != 'AdminServer':
start(nombre)
But the last sequence will fail because will try to start all servers and i'm looking to start only the in the one i'm running the script.
What i believe i'm looking is a way to filter the servers in the current machine.
I'll appreciate any help or advice. I am just starting in wlst scripting.
thanks
I figured it out thanks to this link
I'll just need to filter in a couple of loops like this:
import os
cd('/')
current_m=''
machines = cmo.getMachines()
for m in machines:
hostname = os.environ['HOSTNAME']
nm = m.getNodeManager()
if nm.getListenAddress() in hostname:
current_m=m
servers = cmo.getServers()
for s in servers:
name = s.getName()
if name != 'AdminServer':
ref = getMBean('/Servers/'+name+'/Machine/'+current_m.getName())
if ref != None:
start(name)
I read a date from a SQL Server database through Entity Framework. I return the result to the web page and it's displayed like this :
Date(-658436400000)
I presume it's something about date format but all my attempt to resolve it lead to an exception.
Here the Entity Framework code in VB:
Public Function getEvenements(noFacture As String, bd As eFacturationEntities) As Array
Dim evenements As Array = (
From e In bd.ItemFactures Where e.NoFacture_cs = noFacture
Select e Select New With {
.noEvenement = e.NoEvenement_cn,
.depart = e.DetailFactures.FirstOrDefault.LieuPRCH,
.arrivee = e.DetailFactures.FirstOrDefault.LieuDest,
.nomBeneficiaire = e.Beneficiaire,
.NAM = e.DetailFactures.FirstOrDefault.NAM,
.dateDeNaissance = FormatDateTime(e.DetailFactures.FirstOrDefault.DateNaissance_dt),
.dateDeTransport = e.DetailFactures.FirstOrDefault.PRCH_dt,
.noAs811 = e.DetailFactures.FirstOrDefault.NoAS811}).ToArray()
Return evenements
End Function
Solution : call .toString on the date before sending it to the client.
.dateDeTransport = e.DetailFactures.FirstOrDefault.PRCH_dt.ToString,
But this solution may cause an Exceptionon on some case :
"LINQ to Entities ne reconnaît pas la méthode 'System.String
ToString()', et cette dernière ne peut pas être traduite en expression
de magasin."} System.Exception
(the french tradcution of VS is unclear ...)
Here are my code:-
//Sending mail
if ($this->Session->read('Enrollment.personalinfo_language') == 'English') {
$language = "english";
$subject = "Thank you for submitting your enrollment request to Apna Energy.";
} else {
$language = "spanish";
$subject = "Gracias por enviar su solicitud de inscripci?n a Apna Energy.";
}
$details = $this->Session->read('Enrollment');
$details['plan_name'] = $product['Product']['name'];
$details['rate'] = $plan_rate;
$details['term'] = $product['Term']['term'];
$this->Email->sendAs = 'html';
$this->Email->from = 'Apna Energy <contact#apnaenergy.com>';
$this->Email->to = $this->Session->read('Enrollment.personalinfo_first_name') . ' ' . $this->Session->read('Enrollment.personalinfo_last_name') . '<' . $this->Session->read('Enrollment.personalinfo_email') . '>';
$this->Email->bcc = array('my#mail.com');
$this->Email->subject = $subject;
$this->set('details', $details);
if ($this->Session->read('Enrollment.personalinfo_language') == 'English') {
$template = "enrollment_confirmation";
} else {
$template = "enrollment_confirmation";
}
$this->Email->template = $template;
$this->Email->send();
My problem is if customer fill form they are receiving mail in his/her spam folder.. customer's mail id in "to".. and my mail id in "BCC" for me mail are coming fine in my inbox folder..
I followed two URL but they didn't work out for me..
Cakephp emails going to spam
How do you make sure email you send programmatically is not automatically marked as spam?
Guide me in right direction..
Thanks!!
by using SMTP
with normal PHP your server must be configured properly which is not easy to do as a beginner (MX records need to match the servers ip etc).
So just always stick to SMTP as mailing gateway and you will be fine.
PS: I don't think it has anything to do with your code in general, although it is not very beautiful. for instance: you should cast the array you read from the session to avoid notices thrown:
$details = (array)$this->Session->read('Enrollment');