example - phpmailer
PHP: PEAR mail help (4)
A partir de PHP 5, llamar a un método no estático de otra clase desde el método no estático de otra clase es verboten bajo E_STRICT
. Cuando se PEAR_Mail
paquete PEAR_Mail
, este fue un hack de meta-programación algo oscuro en PHP. Por PEAR_Mail
tanto, PEAR_Mail
es notorio por esto.
El método PEAR::isError()
probablemente debería haber sido un método estático, pero no lo es y asume un contexto de instancia con muchos $this
lanzados. PEAR_Mail
llama estáticamente dentro de su propio contexto de instancia, por lo que PHP infiere el valor de $this
... que es todo tipo de malas noticias.
PEAR_Mail::factory()
debe definirse como static
pero no por razones que solo conocen los autores originales. SIEMPRE generará ese mensaje de advertencia de "método no estático" hasta que se repare el código.
Nota: PEAR_Mail
no se ha tocado desde 2010. ¡No lo use ...! Para alternativas, use Google, Luke!
Estoy probando el paquete de correo pera. Se envía con éxito un correo electrónico, pero dame el siguiente error:
Strict Standards: Non-static method Mail::factory() should not be called statically, assuming $this from incompatible context in C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/ClientPortal/classes/SupportTickets.php on line 356
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Mail/smtp.php on line 365
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 386
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 391
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 398
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 441
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 230
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 445
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Mail/smtp.php on line 376
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 526
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 230
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 529
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 532
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 441
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 230
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 445
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 550
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 694
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 230
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 698
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 706
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 230
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 1017
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 415
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/PHP/PEAR/Net/SMTP.php on line 230
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs/ClientPortal/classes/SupportTickets.php on line 364
Message successfully sent!
Aquí está mi código:
function submitTicket(){
$from = "Billy Jones <[email protected]>";
$to = "helpdesk <[email protected]>";
$subject = "Email Test!";
$body = "email test body";
$host = "***";
$username = "***";
$password = "**********";
$headers = array (''From'' => $from,
''To'' => $to,
''Subject'' => $subject);
$smtp = Mail::factory(''smtp'',
array (''host'' => $host,
''auth'' => true,
''username'' => $username,
''password'' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
}
¿Puede alguien ayudarme aquí?
Hice la misma pregunta aquí y encontré una solución real (en lugar de enmascarar errores). Lea la respuesta a la pregunta a continuación para obtener más detalles, pero básicamente solo siga las tres ediciones a continuación.
¿Cómo no llamar a una función estáticamente en php?
Encuentra php/pear/Mail.php
, ve a la línea 74 y cambia:
function &factory($driver, $params = array())
a
static function &factory($driver, $params = array())
También en php/pear/Mail.php
ve a la línea 253 y cambia:
$addresses = Mail_RFC822::parseAddressList($recipients, ''localhost'', false);
a
$Mail_RFC822 = new Mail_RFC822();
$addresses = $Mail_RFC822->parseAddressList($recipients, ''localhost'', false);
Encuentra php/pear/PEAR.php
, ve a la línea 250 y cambia:
function isError($data, $code = null)
a
static function isError($data, $code = null)
¡Gracias por Amal por mostrar cómo solucionar esto!
Los errores estrictos no impiden que el código funcione.
Simplemente configure la configuración de informes de errores en E_ALL & ~E_STRICT
y desaparecerán mágicamente.
@require_once "Mail.php";
$headers = array (''From'' => $from,''To'' => $to,''Subject'' => $subject);
$smtp = @Mail::factory(''smtp'', array (''host'' => $host,''port'' => $port,''auth'' => true,
''username'' => $UName,''password'' => $UPass));
$mail = @$smtp->send($to, $headers, $body);
if (@PEAR::isError($mail))
{ echo("<p>".$mail->getMessage()."</p>"); }
else
{ echo("<p>Message successfully sent!</p>"); }
Mira: utilicé el signo @
antes de algunas de las variables y métodos. Y de esta manera puede enviar correos electrónicos usando php5. Este es un viejo enfoque, pero debería funcionar. Aunque es posible que se le pregunte si puede habilitar SSL en la configuración, pero eso es pan comido. Disfrutar. Y, por supuesto, una técnica más novedosa pero excelente es el uso de SwiftMailer .