Jump to content

phpmailer


visitor

Recommended Posts

Hi Guys

 

I have now phpmailer installed. Unfortunately I'm getting this error msg “Fatal Error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 30720 bytes)…”

 

my provider tells me that php memory limit is 32 MB! I want to get the data by smtp instead of mail(). Could this play a role as well?

 

Have you got an idea how this problem can be solved?

 

Thanks

 

visitor

Link to comment
Share on other sites

All this means is your script is trying to use more memory than PHP is configured to allow for.  Technically it has nothing to do with PHPMailer.

 

You may want to tell us more about what you're doing and exactly at which point in your script you're running out of memory.

 

Or you can convince your provider to bump up your memory usage or try to do so yourself:

http://drupal.org/node/29268

Link to comment
Share on other sites

how much memory does phpmailer usually consume? Someone told me it's no more than 1 MB and someone else told me that's impossible, it usually consumes not less than 6 MB... which one's true?

 

What are your experiences?

Link to comment
Share on other sites

I've never benchmarked it so I couldn't say.  Are you trying to perform file attachments?  Is the message body very large?  Are you able to identify which area of your code is actually causing the out of memory error?

Link to comment
Share on other sites

Your code is either doing something intended that consumes a lot of memory and you need to increase the amount of available memory (or optimize the code to release existing memory) or you have a logic error in it that is causing it to uncontrollably consume all available memory and increasing the amount of memory will just cause the error to occur at the larger value. In either case, if you cannot find the cause of the problem yourself, you will need to post the code and the complete error message (because it indicates what the code was doing at the time it needed more memory) if you want someone else to help find the cause of the problem.

 

You are expecting a specific error in a specific script (phpmailer in this case) to have exactly one cause. Due to its' general purpose nature, programming does not work like that. Any symptom or error message can have a dozen different possible causes and any logic error in a program can generate different symptoms depending on the environment or at what point in the code it is present. How your complete script is using the phpmailer class and what the code is doing at the point the error is generated is specific to solving the problem. If you aren't, can't, or won't post both pieces of information (the code and the full error message) no one here can specifically help you with the problem.

Link to comment
Share on other sites

Hi Guys

 

this is the error message...

 

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 30720 bytes) in /home/web1234/public_html/phpmailer/class.phpmailer.php on line 785

 

and this is the code...

 

<?php
  error_reporting(E_ALL);
  ini_set("display_errors", true);
  
  function checkForError($text, $errors)
  {
     if (in_array($text, $errors))
        echo "<span style='color:#FF0000'>$text*</span>\n";
     else
       echo "$text*\n";
  }
  
  // Variablen initialisieren
  $firma = $anrede  = $vorname = $nachname = $email     = $strasse = "";
  $ort   = $telefon = $fax     = $betreff  = $nachricht = "";
  
  $errorText = "";
  // Fehler-Array initialisieren
  $errors = array();
     
  // Script wurde vom Formular aufgerufen??
  if (isset($_POST['firma']))
  {
     // Ja, also Überprüfung der Daten
  
     $validEmail = true;
     
     // config laden
     include ("./mailconfig.inc.php");
     
     if (! checkValue ($_POST['firma'], $firma))
       $errors[] = "Company";
       
     if (! checkValue ($_POST['vorname'], $vorname))
       $errors[] = "First Name";
       
     if (! checkValue ($_POST['nachname'], $nachname))
       $errors[] = "Last Name";
       
     if (! checkValue ($_POST['email'], $email))
       $errors[] = "E-Mail";
     
     if (! checkValue ($_POST['telefon'], $telefon))
       $errors[] = "Phone";
       
     if (! checkValue ($_POST['nachricht'], $nachricht))
       $errors[] = "Comment";
       
    // Keine Pflichtfelder
    $anrede = trim($_POST['anrede']);
    
    $ort = stripslashes(trim($_POST['ort']));
    
    $strasse = stripslashes(trim($_POST['strasse']));
    
    $fax = stripslashes(trim($_POST['fax']));
    
    $betreff = isset($_POST['betreff']) ? stripslashes(trim($_POST['betreff'])) : "";
    
    if (!empty($email))
    {
       $validEmail = checkMail($email);
    }
    
    // Fehler vorhanden
    if (count($errors))
       $errorText = "Fields marked with an asterisk * are mandatory: " . implode(", ", $errors);

    // Check der MailAdresse erfolgreich?
    if (!$validEmail)
    {
       $errorText .= (strlen($errorText)) ? "<br /><br />" : "";
       $errorText .= "email address invalid";
    }
    
    // Wenn jetzt kein Fehlertext vorhanden ist, kann die Mail raus,
    if (!strlen ($errorText))
    {
       // Keine Fehler gefunden
       // phpMailer laden
        include ("phpmailer/class.phpmailer.php");
        
        // Texte laden
        include ("./mailtext.inc.php");

        $mail            = new phpmailer();
        $mail->Subject   = PHPMAILER_SUBJECT;
        $mail->FromName  = PHPMAILER_FROM_NAME;
        $mail->PluginDir = PHPMAILER_PLUGIN_DIR;
        $mail->Host      = PHPMAILER_HOST;
        $mail->From      = PHPMAILER_FROM;
        $mail->Username  = PHPMAILER_USER;
        $mail->Password  = PHPMAILER_PASSWORD;
        $mail->IsHTML(true); 
        $mail->AddAddress(PHPMAILER_TO);
     // $mail->SMTPAuth  = true;
     // $mail->Mailer    = "smtp";
        $mail->Body    = $html;
        $mail->AltBody = $txt;
        
        if($mail->Send())
        {
           header ("Location: thanks-contact.htm");
           exit;
        }
        else
          $errorText = "Transmission error, please try again later.";
      
    }
  }
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de-ch" lang="de-ch">
<head>

<title>Contact Form</title>

<META name="keywords" content="Contact Form">
<META name="description" content="Contact Form">
<meta name="generator" content="SuperHTML 7.0">

<style type="text/css">
a:link { font-family:Arial,Verdana,Helvetica,sans-serif; font-size:10pt; color:#D02433; text-decoration:none; border-style:none }
a:visited { font-family:Arial,Verdana,Helvetica,sans-serif; font-size:10pt; color:#D02433; text-decoration:none; border-style:none }
a:hover { font-family:Arial,Verdana,Helvetica,sans-serif; font-size:10pt; text-decoration:none }
a:active { font-family:Arial,Verdana,Helvetica,sans-serif; font-size:10pt; color:#D02433; text-decoration:none; border-style:none }
body { font-family:Arial,Verdana,Helvetica,sans-serif; font-size:10pt; color:#605C88 }
table { font-family:Arial,Verdana,Helvetica,sans-serif; font-size:10pt; color:#605C88; text-align:justify }
p { font-family:Arial,Verdana,Helvetica,sans-serif; font-size:10pt; color:#605C88 }
fieldset { font-family:Arial,Verdana,Helvetica,sans-serif; font-size:10pt; color:#605C88 }

*{
    padding:0;
}

fieldset{
    width:455px;
    margin:8px auto;
    padding:8px;
    background: #ffffff;
}

.dropdown{
    width:145px;
}

.contab{
    width:455px;
}

.btngrp{
    text-align:center;
}

#nachricht{
    width:440px;
}

.norm{
    border:1px solid #7f9db9;
}

#error{
    border:1px solid red;
    padding: 2px;
}
.droperror{
    width:145px;
    border:1px solid red;
}
-->
</style>
</head>
<body>
<center>
<p><a href="index.html" target="_top"><img src="ZEIT8.jpg" border="0" alt="Click on this image to return to the index page"></a></p>
<br>
<?php
  if (strlen($errorText))
     echo "<span id='error'> $errorText </span>\n";
?>
<br>
<!-- Beginn Kontaktformular -->
<FORM ACTION="<?php echo $_SERVER['SCRIPT_NAME']; ?>" METHOD="post">
<div>
  <fieldset>
   <legend>Personal Information</legend>
    <table class="contab">
     <tr>
      <td>
        <?php checkForError("Company", $errors); ?>
      </td>  
      <td><input class="norm" type="text" name="firma" id="company" value="<?php echo $firma; ?>"/></td>
     <td> </td>
    <td> </td>
   </tr>
             
<tr>
  <td>Salutation</td>
   <td><select name="anrede" id="salutation" class="dropdown">
    <option value="" <?php if ($anrede == "") echo "selected=selected"; ?>>please select</option>
     <option value="Mr" <?php if ($anrede == "Herr") echo "selected=selected"; ?>>Mr</option>
      <option value="Mrs" <?php if ($anrede == "Frau") echo "selected=selected"; ?>>Mrs</option>
       </select></td>
        <td> </td>
         <td> </td>
          </tr>           
          <tr>
         <td><?php checkForError("First Name", $errors); ?></td>
        <td><input class="norm"  type="text" name="vorname" id="vorname" value="<?php echo $vorname; ?>"/></td>
       <td><?php checkForError("Last Name", $errors); ?></td>
      <td><input class="norm"  type="text" name="nachname" id="name" value="<?php echo $nachname; ?>"/></td>
     </tr>
                               
<tr>
  <td><?php checkForError("E-Mail", $errors); ?></td>
   <td><input class="norm"  type="text" name="email" id="email" value="<?php echo $email; ?>"/></td>
    <td> </td>
     <td> </td>
      </tr>
                                      
      <tr>
     <td>Street</td>
    <td><input class="norm"  type="text" name="strasse" id="strasse" value="<?php echo $strasse; ?>"/></td>
   <td>ZIP/City</td>
  <td><input class="norm"  type="text" name="ort" id="ort" value="<?php echo $ort; ?>"/></td>
</tr>
                                             
<tr>
  <td><?php checkForError("Phone", $errors); ?></td>
   <td><input class="norm"  type="text" name="telefon" id="telefon" value="<?php echo $telefon; ?>"/></td>
    <td>Fax</td>
     <td><input class="norm"  type="text" name="fax" id="fax" value="<?php echo $fax; ?>"/></td>
      </tr>  
       </table>
        </fieldset>
         </div>
                                                         
         <div class="btngrp">
        <fieldset>
       <legend>Message Topic</legend>
       <input name="betreff" type="radio" value="aaaaa" <?php if ($betreff == "aaaaa") echo "checked=checked"; ?>/>aaaaa 
       <input name="betreff" type="radio" value="bbbbb" <?php if ($betreff == "bbbbb") echo "checked=checked"; ?>/>bbbbb 
       <input name="betreff" type="radio" value="ccccc" <?php if ($betreff == "ccccc") echo "checked=checked"; ?>/>ccccc 
   </fieldset>
  </div>
  
<div>
  <fieldset>
   <legend><?php checkForError("Comment", $errors); ?></legend>
    <textarea id="nachricht" name="nachricht" rows="7" cols="4"><?php echo $nachricht; ?></textarea>
     </fieldset>
      </div>
      
        <div>
       <fieldset>
      <legend></legend>
     <input style="float:left;" type="submit" value="submit" />
    <input style="float:right;" type="reset" value="reset" /> 
   </fieldset>
  <span style="clear:both;"></span>
</div>

<div>
  <fieldset>
   <legend>Important</legend>
    Fields marked with an asterisk * are mandatory<br/>
   </fieldset>
  </div>
</form>
<br>
</body>
</body>
</html>

 

 

maybe you see what's causing this error

 

thanks, visitor

Link to comment
Share on other sites

Edit: Alternatively, what version of phpmailer are you using?

 

I don't directly see anything that would account for an unusually high memory usage. That leaves the things you are loading into memory (and possibly things that the host is autoloading in to memory before your script - are you on a free host that loads a bunch of his content along with your page?)

 

Is the posted code used by itself or is it included into some other file?

 

What does the following line of code show when it is put at the start of your script -

 

echo memory_get_usage();

 

What is in your various include files? Post them xxxxxx'ing out any sensitive information but don't change the basic content the file. How big are PHPMAILER_TO, $html, and $txt?

Link to comment
Share on other sites

Hi

 

it shows...

 

143568

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 30720 bytes) in /home/web1244/public_html/phpmailer/class.phpmailer.php on line 785

 

...and here's the mailconfig.inc.php (what you requested)

<?php
  /*
        mailconfig.inc.php
     */
  // Pfadangaben, hier anpassen, wenn das Script bzzw. die Verzeichnisse 
  // nicht im Hauptverzeichnis liegen
  define ('PEAR_PATH', $_SERVER['DOCUMENT_ROOT'] . "/pear");
  define ('PHPMAILER_PATH', $_SERVER['DOCUMENT_ROOT'] . "phpmailer");
  define ('PHPMAILER_PLUGIN_DIR', "./phpmailer/"); 
  
  // Angaben fuer den Mailversand, hier alle defines anpassen !!!!  
  
  // SMTP-Server, über den die Mail gesendet werden soll
  define ('PHPMAILER_HOST', "xxxxx.net"); 
  // SMTP-Benutzer
  define ('PHPMAILER_USER', "xxxxx");
  // SMTP-Password
  define ('PHPMAILER_PASSWORD', "xxxxx");
  // Absender
  define ('PHPMAILER_FROM', "???");
  // Absender-Name
  define ('PHPMAILER_FROM_NAME', "Kontaktformular <???>");
  // Empfaenger
  define ('PHPMAILER_TO', "info@xxxxx.net");
  // Betreff
  define ('PHPMAILER_SUBJECT', "Nachricht aus Kontaktformular");
  
  // Funktion zum Überprüfen leerer Einträge 
  function checkValue($value, &$resultValue)
  {
     $result = false;
     
     $temp = trim (stripslashes($value));
     
     if (!empty($temp))
     {
        $resultValue = $temp;
        
        $result = true;
     }
     
     return $result;
  }
  
  // Fumtion zur Überprüfung einer eMail-Adresse
  function checkMail($email)
  {
     // Pear-Klassen laden             
     require_once ("PEAR.php");
     include ("Mail/RFC822.php");
     
     // Jetzt die gültigkeit der Mail-Adresse pruefen
     $structure = Mail_RFC822::parseAddressList($email,'',false,true);
     if(PEAR::isError($structure))
        $result = false;
     else
        $result = true;
        
     return $result;
  }
  
  // Pfade setzen
  $path = ini_get("include_path");
  $path .= PATH_SEPARATOR . PEAR_PATH . PATH_SEPARATOR . PHPMAILER_PATH;
  ini_set("include_path", $path);
?>

(mod) Use code tags for large code blocks.

Link to comment
Share on other sites

  • 2 weeks later...

Hi

 

does anyone have a phpmailer script ready without getting error messages like...

 

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 30720 bytes) in /home/web1234/public_html/phpmailer/class.phpmailer.php on line 785

 

thanks,

 

visitor

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.