Guides

PHP Mailer

At https://github.com/Synchro/PHPMailer you can download a completely free php class that emulates the methods and features of Persits Software's AspEmail object.

Installation is quite simple, as you only need to copy the classes class.phpmailer.php and class.smtp.php to your space and include them in the script that will use them.

Uses of the PHPMailer class

  • Example: Sending a message in text format
    <!--?
    include("class.phpmailer.php");
    $mittente = "server@nomedominio.it";
    $nomemittente = "Richiesta Informazioni";
    $destinatario = "info@nomedominio.it";
    $ServerSMTP = "smtp.nomedominio.it";  //server SMTP 
    $corpo_messaggio = "Grazie per averci contattato!!\n"
    	."Cordiali Saluti,\nServizio Clienti";
    
    $messaggio = new PHPMailer;
    // utilizza la classe SMTP invece del comando mail() di php
    $messaggio--->IsSMTP(); 
    $messaggio->SMTPKeepAlive = "true";
    $messaggio->Host  = $ServerSMTP;
    $messaggio->From   = $mittente;
    $messaggio->FromName = $nomemittente;
    $messaggio->AddAddress($destinatario); 
    $messaggio->Body = $corpo_messaggio;
    if(!$messaggio->Send()) {
    	echo "errore nella spedizione: ".$messaggio->ErrorInfo;
    } else {
    	echo "messaggio inviato correttamente";
    }
    ?>

    [Back upstairs]

  • Example: Sending an HTML message
    <!--?
    include("class.phpmailer.php");
    $mittente = "server@nomedominio.it";
    $nomemittente = "Richiesta Informazioni";
    $destinatario = "info@nomedominio.it";
    $ServerSMTP = "smtp.nomedominio.it";  //server SMTP 
    $corpo_messaggio = "Grazie per averci contattato!!\n"
    	."Cordiali Saluti,\nServizio Clienti";
    
    $messaggio = new PHPMailer;
    //messaggio in HTML
    $messaggio--->IsHTML(true);
    // utilizza la classe SMTP invece del comando mail() di php
    $messaggio->IsSMTP(); 
    $messaggio->SMTPKeepAlive = "true";
    $messaggio->Host  = $ServerSMTP;
    $messaggio->From   = $mittente;
    $messaggio->FromName = $nomemittente;
    $messaggio->AddAddress($destinatario); 
    $messaggio->Body = "
    ".$corpo_messaggio."";
    $messaggio->AltBody = $corpo_messaggio;
    if(!$messaggio->Send()) {
    	echo "errore nella spedizione: ".$messaggio->ErrorInfo;
    } else {
    	echo "messaggio inviato correttamente";
    }
    ?>

    [Back upstairs]

  • Example: Sending a message with attachments
    <!--?
    include("class.phpmailer.php");
    $mittente = "server@nomedominio.it";
    $nomemittente = "Richiesta Informazioni";
    $destinatario = "info@nomedominio.it";
    $ServerSMTP = "smtp.nomedominio.it";  //server SMTP 
    $corpo_messaggio = "Grazie per averci contattato!!\n"
    	."Cordiali Saluti,\nServizio Clienti";
    
    $messaggio = new PHPMailer;
    // utilizza la classe SMTP invece del comando mail() di php
    $messaggio--->IsSMTP(); 
    $messaggio->SMTPKeepAlive = "true";
    $messaggio->Host  = $ServerSMTP;
    $messaggio->From   = $mittente;
    $messaggio->FromName = $nomemittente;
    $messaggio->AddAddress($destinatario); 
    $messaggio->Body = $corpo_messaggio;
    
    $messaggio->AddAttachment("/allegati/moduloiscrizione.pdf");      // attach
    $messaggio->AddAttachment("/allegati/istruzioni.pdf"); // attach
    
    if(!$messaggio->Send()) {
    	echo "errore nella spedizione: ".$messaggio->ErrorInfo;
    } else {
    	echo "messaggio inviato correttamente";
    }
    ?>

    [Back upstairs]

  • Example: Sending a message using authenticated or dedicated SMTP

    When messages are sent using an authenticated or dedicated SMTP server, certain information must be present in the code in order to authorise sending through that server.

    Authenticated SMTP server
    In this case, the authenticated SMTP server is
    smtphostauth.interhost.it
    This server is available for all websites hosted by Hosting Solutions, but cannot be used for bulk emailing.
    The code must contain the name of the authenticated Hosting Solutions server together with the credentials (user and password) for authentication. The credentials can be obtained by connecting to the control panel and selecting the 'Configurazione Posta Hosting' icon.

    <!--?
    include("class.phpmailer.php");
    $mittente = "server@nomedominio.it";
    $nomemittente = "Richiesta Informazioni";
    $destinatario = "info@nomedominio.it";
    $ServerSMTP = "smtphostauth.interhost.it";  //server SMTP autenticato Hosting Solutions
    $corpo_messaggio = "Grazie per averci contattato!!\n"
    	."Cordiali Saluti,\nServizio Clienti";
    
    $messaggio = new PHPMailer;
    // utilizza la classe SMTP invece del comando mail() di php
    $messaggio--->IsSMTP(); 
    $messaggio->SMTPAuth   = true;     // abilita autenticazione SMTP
    $messaggio->SMTPKeepAlive = "true";
    $messaggio->Host  = $ServerSMTP;
    $messaggio->Username   = "mio_utente";      // utente server SMTP autenticato
    $messaggio->Password   = "mia_password";    // password server SMTP autenticato
    
    $messaggio->From   = $mittente;
    $messaggio->FromName = $nomemittente;
    $messaggio->AddAddress($destinatario); 
    $messaggio->Body = $corpo_messaggio;
    if(!$messaggio->Send()) {
    	echo "errore nella spedizione: ".$messaggio->ErrorInfo;
    } else {
    	echo "messaggio inviato correttamente";
    }
    ?>

    Dedicated SMTP server

    In this case, the dedicated SMTP server is of the type

    smtp.nomedominio.it/.com/.eu etc.

    can be ordered as an additional service and is also available from IPs that do not belong to Hosting Solutions.
    In the code you must enter the name of the Hosting Solutions dedicated server along with credentials (user and password) for authentication. These credentials were given at the time of subscription to the service.

    <!--?
    include("class.phpmailer.php");
    $mittente = "server@nomedominio.it";
    $nomemittente = "Richiesta Informazioni";
    $destinatario = "info@nomedominio.it";
    $ServerSMTP = "smtp.nomedominio.it";  //esempio di server SMTP dedicato 
    $corpo_messaggio = "Grazie per averci contattato!!\n"
    	."Cordiali Saluti,\nServizio Clienti";
    
    $messaggio = new PHPMailer;
    // utilizza la classe SMTP invece del comando mail() di php
    $messaggio--->IsSMTP(); 
    $messaggio->SMTPAuth   = true;     // abilita autenticazione SMTP
    $messaggio->SMTPKeepAlive = "true";
    $messaggio->Host  = $ServerSMTP;
    $messaggio->Username   = "mio_utente";      // utente server SMTP dedicato
    $messaggio->Password   = "mia_password";    // password server SMTP dedicato
    
    $messaggio->From   = $mittente;
    $messaggio->FromName = $nomemittente;
    $messaggio->AddAddress($destinatario); 
    $messaggio->Body = $corpo_messaggio;
    if(!$messaggio->Send()) {
    	echo "errore nella spedizione: ".$messaggio->ErrorInfo;
    } else {
    	echo "messaggio inviato correttamente";
    }
    ?>

    [Back upstairs]