0
I’m making a code and it’s making this mistake:
Fatal error: Call to a member function send() on a non-object in /home/.../public_html/.../scripts/enviar-email.php on line 63
I wonder if anyone can help me. This is the file indicated in the error:
if(strtolower($_SERVER['REQUEST_METHOD']) == "post"){
include ("Mail.php");
include ("Mail/mime.php");
header('Content-Type: text/html; charset=utf-8');
$recipients = '';
$headers = array
(
'From' => "",
'Reply-To' => $_POST['email'],
'To' => $recipients,
'Subject' => $_POST['assunto'],
'Content-Type' => 'text/html; charset=UTF-8'
);
$html = "<HTML><BODY><font color=red>";
foreach($_POST as $campo => $valor)
{
if (stristr($valor,"Content-Type")) {
header("HTTP/1.0 403 Forbidden");
exit;
}
if($campo != 'redirect')
{
$html .= "<br>---------------------------<br>";
$html .= ucfirst($campo) . " = $valor";
}
}
$html .= "<br>---------------------------";
$html .= "</font></BODY></HTML>";
$mime_params = array(
'text_encoding' => '7bit',
'text_charset' => 'UTF-8',
'html_charset' => 'UTF-8',
'head_charset' => 'UTF-8'
);
$mime = new Mail_mime($crlf);
$mime->setHTMLBody($html);
$body = $mime->get($mime_params);
$headers = $mime->headers($headers);
$params = array
(
'auth' => true,
'host' => 'sensored',
'username' => 'sensored',
'password' => 'sensored'
);
$mail_object =& Mail::factory('smtp', $params);
$result = $mail_object->send($recipients, $headers, $body);
if (PEAR::IsError($result)) {
echo "Erro ao enviar mensagem. (" . $result->getMessage(). ")";
echo "<script>window.history.back();</script>";
}
else{
echo "<script>alert('Mensagem enviada com sucesso');</script>";
echo "<script>window.history.back();</script>";
exit;
}
}
That line
$mail_object =& Mail::factory('smtp', $params);
is with the "&" sign on the instantiation of the Object. This is correct?– Rodrigo Tognin
give a
var_dump
in his$mail_object
and look at the contents of it– JrD
he da null....
– João
Before you call the job
send
you have to make sure that theMail::factory(..)
returned successfully an instance of the object, if it will not give error even, you can 1. check why not returning the object or 2. adds a validation and play an error if $mail_object has null. Put the code ofMail.php
, the error must be there.– fajuchem