Fatal error: Call to undefined method SMTP::setTimeout()

Paperino78

Utente Attivo
30 Giu 2012
409
0
16
Milano
Qualcuno sa dirmi cosa vuol dire questo errore?
PHP:
Fatal error: Call to undefined method SMTP::setTimeout()

l'errore fa riferimento alla riga 1269 del file class.phpmailer.php.
PHP:
 $this->smtp->setTimeout($this->Timeout);
Questo errore me lo da se cerco di inviare una mail utilizzando questo form
PHP:
<?php

# http://localhost/test_site/php/test/MAIL/PHPMailer_Test.php

if (isset($_POST['Submitted'])){

  // estrae e stampa variabili e valori da $_POST
  print '<table width="800" border="0" cellspacing="5" cellpadding="5">';
  while(list($chiave, $valore)=each($_POST)){
    ${$chiave}=trim(strip_tags($valore));
    print "<tr><td>".$chiave." : </td><td>".${$chiave}."</td></tr>";
  }
  if (!GestisciAllegato()) exit;
  print "</table>";

	require_once 'class.phpmailer.php';
	require 'PHPMailerAutoload.php';



//  require_once 'Config_MAIL.php';	// servizi SMTP disponibili
//  SMTPservice(0);			// sceglie il servizio SMTP da usare per invio mail, da Config_MAIL.php

  $mail = new PHPMailer();

  $mail->SMTPDebug = 4;			// attiva log dell'invio, ELIMINARE quando si mette in "produzione"
  $mail->Debugoutput = "error_log";	// scrive messaggi di errore nel log di PHP, si può lasciare sempre

  // impostazione del servizio
  $mail->IsSMTP();

  $mail->Host       = $eM_Host;
  $mail->Port       = $eM_Port;

  $mail->SMTPAuth   = $eM_Auth;
  $mail->SMTPSecure = $eM_Secure;
  $mail->Username   = $eM_username;	// mittente
  $mail->Password   = $eM_password;

  $mail->From       = $eM_username;	// uguale al mittente (alcuni servizi ignorano, altri errore)
  $mail->FromName   = "Mailer";		// nome che precede indirizzo e-mail mittente

  if(!empty($eM_ReplyTo)) $mail->AddReplyTo($eM_ReplyTo, $eM_ReplyToName);	// rispondere a ...

  // impostazione dei destinatari
  $mail->AddAddress($eM_TO1, $eM_TOname1);					// destinatario 1
  if(!empty($eM_TO2)) $mail->AddAddress($eM_TO2, $eM_TOname2);			// destinatario 2
  if(!empty($eM_CC1)) $mail->AddCC($eM_CC1, $eM_CCname1);			// copia conoscenza
  if(!empty($eM_BCC1)) $mail->AddBCC($eM_BCC1, $eM_BCCname1);			// copia conoscenza nascosta

  // impostazione del messaggio
  $mail->WordWrap   = 50;	// set word wrap
  $mail->IsHTML(true);		// send as HTML

  $mail->Subject = $eM_subject;
  $mail->Body    = $eM_body;
  if(!empty($AltBody)) $mail->AltBody = $eM_AltBody;

//  $body = file_get_contents('contents.html');			// testo del messaggio in formato html
//  $mail->MsgHTML($body);

  if(!empty($Allegato)) $mail->AddAttachment($Allegato);	// include l'allegato
//  $mail->AddAttachment("/path/to/file.zip");
//  $mail->AddAttachment("/path/to/image.jpg", "new.jpg");

  // invio della mail
  if(!$mail->Send()) print "ERRORE : MESSAGGIO NON INVIATO";
  else               print "MESSAGGIO INVIATO";

  print "<br /><br /><a href=\"PHPMailer_Test.php\">RIPROVA</a>";
}
else{

  require_once 'Config_MAIL.php';	// servizi SMTP disponibili
  SMTPservice(2);			// sceglie il servizio SMTP da provare per invio mail, da Config_MAIL.php

?>
<!DOCTYPE html>
<form action="PHPMailer_Test.php" method="post" enctype="multipart/form-data" name="eM_form" id="eM_form">
  <table width="500" border="0" cellspacing="5" cellpadding="5">
    <caption>&nbsp;</caption>
    <tr>
      <td colspan="2"><b>PROVA INVIO MAIL CON ALLEGATO (classe PHPMailer 5.2.4)</b></td>
    </tr>
    <tr>
      <td width="165"><label for="eM_Host">Servizio SMTP :</label></td>
      <td width="300"><input type="text" name="eM_Host" id="eM_Host" required value="<?= $eM_Host; ?>" size="50"></td>
    </tr>
    <tr>
      <td width="165"><label for="eM_Port">Porta :</label></td>
      <td width="300"><input type="text" name="eM_Port" id="eM_Port" required value="<?= $eM_Port; ?>" size="50"></td>
    </tr>
    <tr>
      <td><label for="eM_Auth">Autenticazione :</label></td>
      <td>
        <input type='radio' name='eM_Auth' id="eM_Auth" value=false checked /> nessuna
        <span style='padding-left: 10px'> </span>
        <input type='radio' name='eM_Auth' id="eM_Auth" value=true <?php if($eM_Auth == true) echo 'checked'; ?> /> sicura
      </td>
    </tr>
    <tr>
      <td><label for="eM_Secure">Connessione sicura :</label></td>
      <td>
        <input type='radio' name='eM_Secure' id='eM_Secure' value='' checked /> NO
        <span style='padding-left: 10px'> </span>
        <input type='radio' name='eM_Secure' id='eM_Secure' value='tls' <?php if($eM_Secure == 'tls') echo 'checked'; ?> /> TLS
        <span style='padding-left: 10px'> </span>
        <input type='radio' name='eM_Secure' id='eM_Secure' value='ssl' <?php if($eM_Secure == 'ssl') echo 'checked'; ?> /> SSL
      </td>
    </tr>
    <tr>
      <td><label for="eM_username">Utente registrato :</label></td>
      <td><input type="email" name="eM_username" id="eM_username" required value="<?= $eM_username; ?>" size="50"></td>
    </tr>
    <tr>
      <td><label for="eM_password">Password :</label></td>
      <td><input type="text" name="eM_password" id="eM_password" required value="<?= $eM_password; ?>" size="50"></td>
    </tr>
    <tr>
      <td><label for="eM_FROM">e-mail from :</label></td>
      <td><input type="email" name="eM_FROM" id="eM_FROM" required value="<?= $eM_username; ?>" size="50"></td>
    </tr>
    <tr>
      <td><label for="eM_TO1">e-mail to :</label></td>
      <td><input type="email" name="eM_TO1" id="eM_TO1" required value="<?= $eM_TO1; ?>" size="50"></td>
    </tr>
    <tr>
      <td><label for="eM_subject">Oggetto :</label></td>
      <td><input type="text" name="eM_subject" id="eM_subject" required value="oggetto per messaggio di prova" size="50"></td>
    </tr>
    <tr>
      <td><label for="eM_body">Messaggio :</label></td>
      <td><input type="text" name="eM_body" id="eM_body" required value="testo del messaggio di prova" size="50"></td>
    </tr>
    <tr>
      <td><label for="Allegato">Allegato :</label></td>
      <td><input type="file" name="Allegato" id="Allegato" /></td>
    </tr>
    <tr>
      <td colspan="2">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2"><input name="submit" type="submit" id="submit" formaction="PHPMailer_Test.php" formenctype="multipart/form-data" formmethod="POST" value="Invia"></td>
    </tr>
    <tr>
      <td colspan="2"><span class="autorizzo">Autorizzo ai sensi del D. Lgs. 30 Giugno 2003 n. 196 il trattamento dei dati personali trasmessi</span></td>
    </tr>
  </table>
  <input type="hidden" name="eM_TOname1" value="">
  <input type="hidden" name="eM_TO2" value="">
  <input type="hidden" name="eM_TOname2" value="">
  <input type="hidden" name="eM_CC1" value="">
  <input type="hidden" name="eM_CCname1" value="">
  <input type="hidden" name="eM_BCC1" value="">
  <input type="hidden" name="eM_BCCname1" value="">
  <input type="hidden" name="eM_ReplyTo" value="">
  <input type="hidden" name="eM_ReplyToName" value="">
  <input type="hidden" name="eM_AltBody" value='This is the body in plain text for non-HTML mail clients'>

  <input type="hidden" name="Submitted" value="1" />
</form>
</html>
<?PHP
}

function GestisciAllegato() {
  global $Allegato;

  $Allegato = "";
  if ($_FILES["Allegato"]["error"] == 4)
    return true;
  else {
    if ($_FILES["Allegato"]["error"] > 0) {
      print "<font color=red>Upload Return Code: ".$_FILES["Allegato"]["error"]."</font><br />";
      return false;
  } }

  $Allegato_name = $_FILES["Allegato"]["name"];
  $Allegato_type = $_FILES["Allegato"]["type"];
  $Allegato_size = $_FILES["Allegato"]["size"] / 1024;
  $Allegato_temp = $_FILES["Allegato"]["tmp_name"];
  $Allegato_path = dirname($_FILES["Allegato"]["tmp_name"]);
  $Allegato      = $Allegato_path."/".$Allegato_name;

  if ( ($Allegato_size > 2000000)
  || ( ($Allegato_type <> "image/gif")
    && ($Allegato_type <> "image/jpeg")
    && ($Allegato_type <> "image/pjpeg")
    && ($Allegato_type <> "application/zip")
    && ($Allegato_type <> "application/x-zip-compressed")
    && ($Allegato_type <> "application/x-shockwave-flash")
  ) ) {
    print "<font color=red>Dimensione o Tipo di file non valido</font><br />";
//  return false;
  }

  print "<tr><td>Upload : </td><td>".$Allegato_name."</td></tr>";
  print "<tr><td>Type : </td><td>".$Allegato_type."</td></tr>";
  print "<tr><td>Size (kB) : </td><td>".$Allegato_size."</td></tr>";
  print "<tr><td>Stored in : </td><td>".$Allegato_temp."</td></tr>";
  print "<tr><td>folder : </td><td>".$Allegato_path."</td></tr>";
  print "<tr><td>new file : </td><td>".$Allegato."</td></tr>";

  if (file_exists($Allegato)) {
    print "<font color=red>".$Allegato." esiste sul server<br />";
    print "lo cancello per sostituirlo con il nuovo file trasferito</font><br />";
    unlink($Allegato);
  }

// move_uploaded_file($Allegato_temp, $UploadPath.$Allegato_name); <<-- non gestito

  rename ($Allegato_temp, $Allegato);
  if (file_exists($Allegato)) {
    print "<font color=green>".$Allegato." Upload eseguito con successo</font><br />";
  }
  return true;
}
?>
 

marino51

Utente Attivo
28 Feb 2013
3.203
207
63
Lombardia
devi solo sostituire i 2 require sottostanti,

PHP:
require_once 'class.phpmailer.php'; 
require 'PHPMailerAutoload.php';

con il solo,

PHP:
require_once 'xPHPMailer/PHPMailerAutoload.php';

attento, il mio path é "xPHPMailer/" per essere sicuro di lavorare con la nuova versione,
tu metti quello dove hai "parcheggiato" la tua classe

ti segnalo anche che, nella nuova versione hanno sistemato la gestione dei messaggi,
per vedere i messaggi del colloquio con il server, nel browser, devi modificare

PHP:
$mail->SMTPDebug = 4;
$mail->Debugoutput = "error_log";

con

PHP:
$mail->SMTPDebug = 4;
$mail->Debugoutput = "html";

ciao
Marino
 

Paperino78

Utente Attivo
30 Giu 2012
409
0
16
Milano
Ho corretto come hai consigliato tu così:
PHP:
	require_once 'PHPMailerAutoload.php';


  $mail = new PHPMailer();

  $mail->SMTPDebug = 4;			// attiva log dell'invio, ELIMINARE quando si mette in "produzione"
  $mail->Debugoutput = "html";	// scrive messaggi di errore nel log di PHP, si può lasciare sempre

  // impostazione del servizio
  $mail->IsSMTP();
e purtroppo mi appare ancora lo stesso errore. Ovviamente i percorsi sono corretti.
 

marino51

Utente Attivo
28 Feb 2013
3.203
207
63
Lombardia
purtroppo non riesco a riprodurre l'errore che ottieni,

ho preso anche lo script che hai postato tu ed eseguendolo è andato, senza modifiche e senza problemi,

trovo strano che non hai nessun path nel richiamare la classe PHPMailer, questo mi fa pensare che puoi avere mischiato files di versioni diverse, ti consiglio di scompattare nuovamente la distribuzione,
mantenendola nella sua directory richiamandola, poi, da lì,

se usi autoloader, puoi evitare di chiamare 'class.phpmailer.php'

fammi sapere, ciao
Marino
 

Paperino78

Utente Attivo
30 Giu 2012
409
0
16
Milano
Ciao, allora stasera con un attimo più di calma ho controllato tutto e mi sono accorto che avevo scaricato qualcosa di sbagliato nel file. Errore mio, non avevo visto che il download del phpmailer era a destra della pagina web, scaricabile come file zip.:dipser: :crying: Con il senno di poi potrei dire che questo thread potevo evitarlo. Vabbè comunque grazie ancora marino51
 
Discussioni simili
Autore Titolo Forum Risposte Data
L [PHP] Fatal error: Call to a member function prepare() on null in PHP 0
C [PHP] Errore "Fatal error: Call to undefined function getTotalUsers()" PHP 2
U [PHP] Fatal error: Call to a member function Query() PHP 1
G Fatal error: Uncaught Error: Call to undefined method UserController PHP 0
O Fatal error: Call to undefined function testNome() in C:\xampp\...\...\index.php on line 51 PHP 4
JackIlPazzo Fatal error: Call to a member function execute() on a non-object PHP 2
JackIlPazzo PHP: Fatal error: Call to a member function bind_param() on a non-object PHP 0
M fatal error: Call to undefined function gdrcd_filter() PHP 6
T Fatal error: Call to a member function show_crom() on a non-object PHP 1
F Fatal error: Call to undefined function PHP 9
L Fatal error: Call to undefined method Paging::listaPagine() PHP 2
L Fatal error: Call to undefined function virtual() in C:\Inetpub\wwwroot\... PHP 1
U Campo vuoto data errore Fatal error: PHP 2
I Fatal error: Query Failed! SQL: SELECT * INTO OUTFILE PHP 1
D [PHP] Fatal error: Class 'COM' not found in C:\..... PHP 6
T [PHP] aiuto....Fatal error: Uncaught Error:non riesco a capire PHP 1
J [PHP] Recoverable fatal error: PHP 4
J [PHP] fatal error PHP 1
C PHP errore Fatal Error: Allowed Memory Size of ... Bytes Exhausted PHP 7
Antoyosh Fatal error con Wordpress WordPress 5
filippino Fatal error: Cannot redeclare (function) PHP 2
C errore su wordpress _ fatal error PHP 1
S [RISOLTO] Fatal error in Upload Multiplo di immagini PHP 2
F Fatal error: t3import not found object Joomla 0
Mauro Guardiani Fatal error HTML e CSS 2
T Fatal error: Cannot access empty property PHP 2
G Fatal error: Uncaught exception 'PDOException' PHP 12
LaKanka Fatal error upload immagini PHP 19
S 404 Error " Page not Find" Error SEO e Posizionamento 0
L Error Code: 1215. Cannot add foreign key constraint MySQL 3
M HTTP Status 500 - Internal Server Error. Java 0
A Uncaught Error: jQuery 1
F Uncaught (in promise) Error: 3000ms timeout exceeded Javascript 0
W ADODB.Recordset error '800a0bb9' Classic ASP 2
D error text in table HTML e CSS 11
W Microsoft OLE DB Provider for Visual FoxPro error '80040e14' Function name is missing ). Classic ASP 0
W Parse error: syntax error, unexpected '$result' (T_VARIABLE) PHP 4
W Errore di run-time di Microsoft VBScript error '800a0035' Impossibile trovare il file Classic ASP 0
G Upload file error Apache 0
A Server Apache immagine not found (ERROR 404) Apache 5
T MySQL ERROR 1064 MySQL 1
T [PHP] ...Parse error che non c'è... PHP 7
V [MySQL] You have an error in your SQL syntax MySQL 1
G PHPMailer: SMTP error Gmail PHP 8
G [WordPress] [PHP] Parse error: syntax error, unexpected '$x332cbce1' WordPress 2
I [PHP] Login Facebook SDK returned an error: No URL set! PHP 0
bubino8 [PHP] Query syntax error PHP 6
momeraths [WordPress] cURL error: problema aggiornamento/installazione plugin WordPress 4
A [PHP] FPDF error: Some data has already been output, can't send PDF file PHP 5
otto9due Error anomalo durante invio dati $.ajax Ajax 20

Discussioni simili