I have a page where I check if the user has filled all the fields of a form
but when trying to show the messages to the user script
returns me an error, I'm doing this:
class SendEmail { private $nome; private $email; private $telefone; private $cidade; private $uf; private $assunto; private $mensagem; private $receive_mail; public function __construct($data) { $this->receive_mail = "[email protected]"; try { if (count($data) sendMail(); } catch (Exception $e) { return json_encode(array('success'=>'0','errors'=>$e->getMessage())); } } public function sendMail() { $subject = $this->assunto; $body = "From {$this->nome}, \n\n{nl2br($this->mensagem)}"; $headers = 'From: ' . $this->email . "\r\n" . 'Reply-To: ' . $this->email . "\r\n" . 'Content-type: text/html; charset=utf-8' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); if (mail($this->receive_mail, $this->assunto, $body, $headers)) { return json_encode(array('success'=>'1','message'=>'Mensagem enviada com sucesso!')); } else { throw new Exception("Ocorreu um erro no envio da mensagem, por favor, tente mais tarde."); } } } if ($_POST) { // Aqui ele retornará um JSON com os erros ou a mensagem de sucesso echo json_encode(new SendMail($_POST)); }
And the whole message is this:
Catchable fatal error: Object of class SendEmail could not be converted to string in /home/anc/public_html/anc/sendEmail.php on line 84
The problem is that I'm trying to show Objeto
as string
so I read in the php
manual, but I could not solve it.