User Tools

Site Tools


informatica:linux:php:mail

Instalamos paquetes necesarios de PEAR. Yo he instalado: php-mail, php5-dev, php-net-mail, php-net-smtp.
He creado la funcion /usr/share/php/correo
Devuelve OK o el error si no se envía:

<?php
function correo ($arg1,$arg2,$arg3,$arg4)
{
require_once "Mail.php";

$from = $arg1;
$to = $arg2;
$subject = $arg3;
$body = $arg4;

$host = "smtp.jazztel.es";
$username = "lobo99.lobo99.jazztel.es";
$password = "lobo99";

$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))
{
return $mail->getMessage();
}
else
{
return "OK";
}
}
?>

Para enviar un correo. El echo es para que devuelva la salida OK o el error:

<?
include correo;
echo correo ("Jose <joselegido@gmail.com>","Pepe <jlegido@mailext.com>","Hola","Adios");
echo correo ("joselegido@gmail.com","jlegido@mailext.com","Hola","Adios");
?>
informatica/linux/php/mail.txt · Last modified: 2015/04/13 20:19 by 127.0.0.1