AS
PHP
Inviare una mail con phpmailer
Codice
<?php
require_once('class.phpmailer.php');
require_once('class.smtp.php');
// personalizzare a seconda della posizione dei file
function myPhpMailer($to)
{
$mail = new PHPMailer(true);
try
{
$mail->SMTPDebug = 2;//Enable verbose debug output
$mail->isSMTP();//Set mailer to use SMTP
$mail->Host = 'smtps.xxxxxxxx';//SMTP server
$mail->SMTPAuth = true;//Enable SMTP authentication
$mail->Username = 'my user name';//SMTP username
$mail->Password = 'xxxxxxxx';//SMTP password
$mail->SMTPSecure = 'ssl';//'tls'/'ssl'
$mail->Port = 465;//Port to connect to
$mail->setFrom('xxxxx@xxxxx.xx', 'My Name');//From
$mail->addAddress($to);//Recipient, name is optional
$mail->AddReplyTo('xxxxx@xxxxx.xx', 'My Name');//Reply to
$mail->isHTML(true);//Set email format to HTML
$mail->Subject = 'Oggetto della mail';
$mail->Body='
<div>Corpo della mail</div>
';
$mail->AltBody = 'Testo alternativo, se non supportato HTML';
$mail->SMTPDebug = 0;
$mail->send();
return true;
}
catch(Exception $e)
{
$mail->SMTPDebug = 0;
return false;
}
}
$recipient="xxxxx@xxxxx.xx";
if(myPhpMailer($recipient)==TRUE)
{
// Mail inviata correttamente
}
else
{
// Errore
}
?>
Download dei file
I file class.phpmailer.php e class.smtp.php sono facilmente reperibili in rete.
Per comodità metto a disposizione una cartella .zip contenente entrambi.
link per il download della cartella compressa
Test