There's some trick i can do to check if the $cake_email->send() get Connection timed out ?For example: if I get a Connection Timed Out, i use a especific setFlash warning the user about the time out and redirect him to somewhere.
In my case, the email is something optional , if it sends: nice! If it don't: no problem, just need to let the user know this
Actualy I'm using IF to check if it get some error, but this didn't catch the time out error
$cake_email = new CakeEmail('gmail');
$cake_email->emailFormat('html');
$cake_email->to($dados['Requisitante']['email']);
$cake_email->template('atualizacaoRequisicao', 'default');
$cake_email->subject('ATUALIZAÇÃO DE REQUISICÃO');
$cake_email->viewVars(array('dados' => $dados));
if($cake_email->send()){
$this->setFlash('A requisição foi salva e o email notificando a alteração foi enviado para '.$dados['Requisitante']['email'], 'flash_success');
} else {
$this->setFlash('A requisição foi alterada, porém o email nao foi enviado', 'flash_info');
}
STLMikey 's comment (try/catch) solved my problem! Much more simple than I expected
I'll just let my actual code here in case of helping someone else with the same problem.
try {
if($cake_email->send()){
$this->setFlash('A requisição foi salva e o email notificando a alteração foi enviado para '.$dados['Requisitante']['email'], 'flash_success');
} else{
$this->setFlash('A requisição foi alterada, porém o email nao foi enviado', 'flash_info');
}
} catch(Exception $ex){
$this->setFlash('A requisição foi alterada, porém o email não foi enviado ('.$ex->getMessage().')<br>Você pode atualizar a requisição novamente para tentar reenviar o email', 'flash_info');
return $this->redirect(array('action' => 'edit', $dados['Requisicao']['id']));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.