Blind99 Posted March 20, 2008 Share Posted March 20, 2008 Hey, as the title says it im a total newb but still, ive been trying to script an anonymous email message form, but im getting an error and I cant figure it out. Heres my code, please help . <?php class maxContact { var $subjectText = "Blind99 Anonymous l337 Mail"; var $targetEmail = ""; var $mailFormat = "text/plain"; var $fieldList; var $errorList; var $email = ''; var $name = ''; var $message = ''; var $additionalText = ''; function showForm(){ $message = ''; echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">'; echo ' <table>'; echo ' <tr><td>Name:</td></tr>' .' <tr><td><input type="text" name="name" value="'.$this->name.'" /></td></tr>'; echo ' <tr><td>Email:</td></tr>' .' <tr><td><input type="text" name="email" value="'.$this->email.'"/></td></tr>'; echo ' <tr><td>Target Mail:</td></tr>' .' <tr><td><input type="text"name="targetEmail" value="'.$this->targetEmail.'"/></td></tr>'; echo ' <tr><td>Subject:</td></tr>' .' <tr><td><input type="text"name="targetEmail" value="'.$this->subjectText.'"/></td></tr>'; echo ' <tr><td>Message:</td></tr>' .' <tr><td ><textarea cols="40" rows="6" name="message">'.$this->message.'</textarea></td></tr>' .'<tr><td><input type="submit" name="submitBtn" class="sbtn" value="Send" /></td></tr>'; echo ' </table>'; echo '</form>'; } function sendMail() { $subject = $this->subjectText; $from = "From: $this->name <$this->email>\r\nReply-To: $this->email\r\n"; $header = "MIME-Version: 1.0\r\n"."Content-type: $this->mailFormat; charset=iso-8859-1\r\n"; $content = $this->message; if ($this->additionalText != ''){ $content .= "\r\n\r\nAdditional information:\r\n\r\n" .$this->additionalText; } $content = wordwrap($content,70); @mail($this->targetEmail,$subject,$content,$from.$header); } function isValidEmail($email){ $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"; if (eregi($pattern, $email)){ return true; } else { return false; } } function processForm(){ if (isset($_POST['submitBtn'])){ $email = isset($_POST['email']) ? trim($_POST['email']) : ''; $name = isset($_POST['name']) ? trim($_POST['name']) : ''; $message = isset($_POST['message']) ? trim($_POST['message']) : ''; if (!$this->isValidEmail($email)) $this->errorList[] = "Invalid email address!"; //line 76 below if (strlen($name)<2) $this->errorList[] = "Invalid name! It must be at least 2 characters long."; //line 76 above if (strlen($message)<1) $this->errorList[] = "Invalid message! It must be at least 2 characters long."; $this->email = $email; $this->name = $name; $this->message = htmlspecialchars($message); foreach ($this->fieldList as $key=>$value) { if (isset($_POST[$value['fieldName']])) { $this->fieldList[$key]['value'] = $_POST[$value['fieldName']]; $this->additionalText .= $value['caption'] . " : " . $_POST[$value['fieldName']]."\r\n"; } } if (sizeof($this->errorList) > 0){ $this->showErrors(); $this->showForm(); } else { $this->sendMail(); $this->showInfo(); } } else { $this->showForm(); } } function showErrors(){ echo '<ul class="error">'; foreach ($this->errorList as $value) { echo " <li>$value</li>"; } echo "</ul>"; } function showInfo(){ echo "<p>Message Sent!</p>"; } } ?> Im getting a shit at line 76. Warning: Invalid argument supplied for foreach() in /home/pasdoy/public_html/gon/AnonymousMail/script.class.php on line 76 I installed the lil script here http://napsko.com/gon/AnonymousMail/ So thats it , please help me thanks in advance Link to comment https://forums.phpfreaks.com/topic/97143-php-total-newb-trying-to-script/ Share on other sites More sharing options...
soycharliente Posted March 20, 2008 Share Posted March 20, 2008 You're trying to loop through fieldList, but it's not an array. Would help to post the actual error so I don't have to go to your site and break it. EDIT: Was that really there the first time? Link to comment https://forums.phpfreaks.com/topic/97143-php-total-newb-trying-to-script/#findComment-497064 Share on other sites More sharing options...
Blind99 Posted March 20, 2008 Author Share Posted March 20, 2008 heuu , hmm ok... How would you correct that if you were me to make it work Link to comment https://forums.phpfreaks.com/topic/97143-php-total-newb-trying-to-script/#findComment-497202 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.