By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,315 Members | 2,150 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,315 IT Pros & Developers. It's quick & easy.

form processing problem

Dormilich
Expert Mod 5K+
P: 8,639
this is a follow-up thread to this one.
http://bytes.com/topic/html-css/answ...tted-sometimes

I figured out that the mail sending class triggers the described error. unfortunately, no error message is given by the system.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. class Mail_Tabelle extends Mail_DB
  3. {
  4.     protected $description = false;
  5.     const TBL_HEAD = '
  6.     <thead>
  7.         <tr>
  8.             <th id="spalte1">Datum</th>
  9.             <th id="spalte2">Nachricht</th>
  10.         </tr>
  11.     </thead>';
  12.  
  13.     function __construct()
  14.     {
  15.         parent::load();
  16.  
  17.         if (isset($_POST['senden']))
  18.         {
  19.             $this->sendMail();
  20.         }
  21.         if (isset($_GET['desc']) and preg_match('#^\d+$#', $_GET['desc']) == 1)
  22.         {
  23.             $this->description = (int) $_GET['desc'];
  24.         }
  25.     }
  26.  
  27.     public function printTable()
  28.     {
  29.         $anzahl = count(parent::$DB_mails);
  30.         if ($anzahl == 0) return false;
  31.         echo '
  32. <table id="blog">', self::TBL_HEAD, '
  33.     <tbody>';
  34.         for ($i=0; $i<$anzahl; ++$i)
  35.         {
  36.             $desc = ($this->description === $i) ? true : $i;
  37.             parent::$DB_mails[$i]->printTableRow($desc); 
  38.         }
  39.         echo '
  40.     </tbody>
  41. </table>
  42. ';
  43.     }
  44.  
  45.     protected function sendMail()
  46.     {
  47.         $text = $_POST["NLG"];
  48.         $betreff = $_POST["betreff"];
  49.         if (!$text or !$betreff) return false;
  50.         $adr = $this->prepareMail();
  51.         $msg = "[...]";
  52.         $RS = new Mail_Verteiler($msg, $betreff); // problem is HERE
  53.         $RS->setList($adr);
  54.         $RS->sendMails();
  55.         $this->saveMail();
  56.     }
  57. }
  58. ?>
I suspect something with the loading isn't going right, because it doesn't matter if I uncomment the parent constructor (line 11) or not.

can anyone give me an idea how to get some clues where the problem's cause is?
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require_once LIB_DIR . "Swift/Plugin/Decorator.php";
  3.  
  4. class Mail_Verteiler extends KBL_Mail
  5. {
  6.     protected $to = NULL;
  7.     protected $replace = array();
  8.  
  9.     function __construct($msg, $subj)
  10.     {
  11.         parent::__construct($msg, $subj);
  12.     }
  13.  
  14.     public function setList($empfanger)
  15.     {
  16.         if (!is_array($empfanger)) return false;
  17.         if (!($this->to instanceof Swift_RecipientList))
  18.         {
  19.             $this->to = new Swift_RecipientList;
  20.         }
  21.         foreach ($empfanger as $person)
  22.         {
  23.             $Name = ($person['Name']) ? $person['Name'] : 'Leser';
  24.             $this->to->addTo($person['Email']);
  25.             $this->replace[] = array('{name}' => $Name, '{UID}' => $person['UID']);
  26.         }
  27.         return true;
  28.     }
  29.  
  30.     public function sendMails($from = 'email@host.tld')
  31.     {
  32.         if (!($this->to instanceof Swift_RecipientList)) 
  33.         {
  34.             $this->sent = false;
  35.             return false;
  36.         }
  37.         $this->mail->attachPlugin(new Swift_Plugin_Decorator($this->replace), "decorator");
  38.         return $this->sendTo($this->to, $from);
  39.     }
  40. }
  41. ?>
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require_once LIB_DIR . "Swift.php";
  3. require_once LIB_DIR . "Swift/Connection/SMTP.php";
  4. require_once CONF_DIR . "conf.mail.php";
  5.  
  6. /**
  7.  * a little wrapper around Swift_Mail for sending error reports.
  8.  * only basic email sending is intended, so for HTML form results
  9.  * use Swift directly.
  10.  */
  11. class KBL_Mail
  12. {
  13.     /**
  14.      * @var (object) $mail      Swift Mail (root) class
  15.      * @var (bool) $sent        success of sending the email
  16.      * @var (string) $subject   email subject
  17.      * @var (string) $message   email message
  18.      */
  19.     protected $mail = NULL;
  20.     protected $sent = false;
  21.     public    $subject;
  22.     public    $message;
  23.  
  24.     /**
  25.      * establish the connection to the SMTP server
  26.      * load subject & message
  27.      */
  28.     function __construct($message = '', $subject = 'Fehlerbericht')
  29.     {
  30.         # connect to the mail server
  31.         $smtp = new Swift_Connection_SMTP(KBL_MAIL_SMTP_STD, 587, Swift_Connection_SMTP::ENC_OFF);
  32.         $smtp->setUsername(KBL_MAIL_USER);
  33.         $smtp->setPassword(KBL_MAIL_PASS);
  34.  
  35.         # create swiftmailer class
  36.         $this->mail = new Swift($smtp);
  37.         $this->subject = $subject;
  38.         $this->message = $message;
  39.     }
  40.  
  41.     function __destruct()
  42.     {
  43.         $this->mail->disconnect();
  44.     }
  45.  
  46.     /**
  47.      * send email
  48.      *
  49.      * @param (string) $to       recipient (To:)
  50.      * @param (string) $from     sender (From:)
  51.      * @return (void)
  52.      */
  53.     public function sendTo($to = KBL_MAILTO_ADMIN, $from = 'email@host.tld')
  54.     {
  55.         $swift_msg = new Swift_Message($this->subject, $this->message);
  56.         $swift_msg->headers->setLanguage("de");
  57.         $this->sent = $this->mail->send($swift_msg, $to, $from);
  58.         return $this->sent;
  59.     }
  60. }
  61. ?>
Feb 15 '09 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.