Primero nos aseguramos que las librearias de PEAR estén instaladas, desde la interfaz de línea de comandos:
[bash]
$ sudo pear install mail
$ sudo pear install Net_SMTP
[/bash]
Luego, creamos la clase en el archivo mailer.class.php:
require_once "Mail.php";
class Mailer {
static $to;
static $from;
static $subject;
static $message;
static $html = false;
static function send() {
$host = "mail.example.com";
$username = "micorreo@example.com";
$password = "mipassword";
$headers['From'] = self::$from;
$headers['To'] = self::$to;
$headers['Subject'] = self::$subject;
if ( self::$html ) {
$headers['Content-Type'] = 'text/html; charset=ISO-8859-1';
}
$config['host'] = $host;
$config['auth'] = true;
$config['username'] = $username;
$config['password'] = $password;
$smtp =
Mail::factory(
'smtp',
$config
);
$mail =
$smtp->send(
self::$to,
$headers,
self::$message
);
if ( PEAR::isError( $mail ) ) {
throw new Exception( $mail->getMessage() );
} else {
return $mail;
} // end if PEAR error
} // end function send
} // end class Mailer
Se utiliza así:
[php]
Mailer::$from = ‘luis@espino.info’;
Mailer::$to = ‘miotrocorreo@mail.com’;
Mailer::$subject = ‘Prueba de correo’;
Mailer::$message = ‘
Este es un mensaje
‘;
Mailer::$html = true;
$mail = Mailer::send();
[/php]
Happy coding! 🙂
admin
May 19, 2016
Uncategorized
No Comment