SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2001
    Posts
    478
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with PHP formmail error

    Hi,

    This script ( http://members.rogers.com/mail4donpro)was working perfectly a week ago however now I get this error..

    Warning: Cannot modify header information - headers already sent in /home/ihostweb/public_html/htmlmail/formmail.php on line 824

    Here's the form

    http://www.ihost-websites.com/htmlmail/newsletter.htm

    I originally set up this form/script to show folks how to send html email and/or use it for one's website.

    Please advise.
    Herman Drost
    http://www.isitebuild.com
    Affordable Web Site Design
    and Web Site Hosting

  2. #2
    SitePoint Addict seanmayhew's Avatar
    Join Date
    Aug 2002
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post the code for formmail.php?

  3. #3
    SitePoint Evangelist
    Join Date
    Jan 2001
    Posts
    478
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for responding...
    Here's the formmail script - do a scan and let me know if you see anything out of place - I only changed the referrers info.

    There are 8 other scripts that go with it ie email validation, email functions etc however this is the main formmail script.

    I hope it is readable - here goes..

    <?PHP
    /****************************************************************************
    * File for assigning all of the variables passed into the form to a generic *
    * array variable (required). This is actually the decode_vars() function. *
    * I moved it into it's own file as I use it throughout my web site, calling *
    * it from several scripts. *
    ****************************************************************************/
    include('function.decodevars.php');
    /****************************************************************************
    * Class for sending e-mails. Supports attachments and HTML. (required) *
    ****************************************************************************/
    include('class.phpmailer.php');
    /****************************************************************************
    * Class for validating e-mail address. (required) *
    ****************************************************************************/
    include('email_validation.php');
    /****************************************************************************
    * Custom email function file (optional) *
    * You can include your custom email function in this file. See *
    * 'custom_email_function' for further information. *
    ****************************************************************************/
    if (file_exists('email_functions.php')) {
    include('email_functions.php');
    }
    /****************************************************************************
    * Custom error function file (optional) *
    * You can include your custom error function in this file. See *
    * 'custom_error_function' for further information. *
    ****************************************************************************/
    if (file_exists('error_functions.php')) {
    include('error_functions.php');
    }
    define('VERSION','Classic v1.06.0');
    define('MANUAL','http://www.boaddrink.com/projects/phpformmail/readme.php');
    define('CHECK_REFERER', false);
    // +------------------------------------------------------------------------+
    // | PHPFormMail |
    // | Copyright (c) 1999 Andrew Riley (webmaster@boaddrink.com) |
    // | |
    // | This program is free software; you can redistribute it and/or |
    // | modify it under the terms of the GNU General Public License |
    // | as published by the Free Software Foundation; either version 2 |
    // | of the License, or (at your option) any later version. |
    // | |
    // | This program is distributed in the hope that it will be useful, |
    // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
    // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
    // | GNU General Public License for more details. |
    // | |
    // | You should have received a copy of the GNU General Public License |
    // | along with this program; if not, write to the Free Software |
    // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
    // | USA. |
    // | |
    // +------------------------------------------------------------------------+
    // | |
    // | If you run into any problems, pleas read the readme_formmail.txt. |
    // | If that does not help, check out http://www.boaddrink.com. |
    // | |
    // | For more info, please visit http://www.boaddrink.com or read the |
    // | readme file included. |
    // +------------------------------------------------------------------------+
    // | |
    // | Value array fix by: Konrad Maqestieau |
    // | check_recipients reset() fix by: Don |
    // | servertime_offset code by: desolate
    // | |
    // +------------------------------------------------------------------------+ |
    $bad_referer = '';
    $bad_email = '';
    $bad_function = '';
    $referers = array ("ihost-websites.com","www.ihost-websites.com","209.123.240.161");
    $valid_env = array("REMOTE_HOST", "REMOTE_ADDR", "REMOTE_USER", "HTTP_USER_AGENT");
    // +------------------------------------------------------------------------+
    // | STOP EDITING! The only two variables that need to be updated are |
    // | $referers and $valid_env |
    // +------------------------------------------------------------------------+
    $recipients = $referers;
    $errors = $fieldname_lookup = array();
    $invis_array = array('recipient','subject','required','redirect',
    'print_blank_fields','env_report','sort',
    'missing_fields_redirect','title','bgcolor',
    'text_color','link_color','alink_color',
    'vlink_color','background','subject','title',
    'link','css','return_link_title',
    'return_link_url','recipient_cc','recipient_bcc',
    'priority','redirect_values','hidden','alias',
    'mail_newline', 'gmt_offset', 'email_validate',
    'validation_type','file_name', 'reply_to',
    'custom_email_function','custom_error_function',
    'sessions');
    /****************************************************************
    * fake_in_array() is only used in PHP3 since PHP4 has a native *
    * in_array. Depending on what version of PHP you are running *
    * the script will determine what is the best function to run *
    * --- THER IS NO LONGER ANY REASON TO DELETE THIS FUNCTION --- *
    * Function renamed in 1.04.0 *
    ****************************************************************/
    function fake_in_array($needle, $haystack)
    {
    $found = false;
    while (list($key,$val) = each ($haystack)) {
    if ($needle == $val)
    $found = true;
    }
    return $found;
    }
    /****************************************************************
    * check_referer() breaks up the enviromental variable *
    * HTTP_REFERER by "/" and then checks to see if the second *
    * member of the array (from the explode) matches any of the *
    * domains listed in the $referers array (declaired at top) *
    ****************************************************************/
    function check_referer($referers)
    {
    global $errors,$bad_referer;
    if (count($referers)) {
    if (getenv('HTTP_REFERER')) {
    $temp = explode('/', getenv('HTTP_REFERER'));
    $found = false;
    while (list(,$stored_referer) = each($referers)) {
    if (eregi('^' . $stored_referer . '$', $temp[2]))
    $found = true;
    }
    if (!$found) {
    $errors[] = '1|You are coming from an unauthorized domain. Please read the manual section titled &quot;<a href="' . MANUAL . '#setting_up" target="_blank">Setting Up the PHPFormMail Script</a>&quot;.';
    error_log('[PHPFormMail] Illegal Referer. (' . getenv('HTTP_REFERER') . ')', 0);
    if ($bad_referer == '')
    $bad_referer = '1';
    else
    $bad_referer .= ',1';
    }
    return $found;
    } else {
    $errors[] = '0|Sorry, but I cannot figure out who sent you here. Your browser is not sending an HTTP_REFERER. If you are using Norton Firewall (any version), please see the <a href="<A href="http://service1.symantec.com/SUPPORT/nip.nsf/5a5e9c8a8ac2ec3c882568f60060f23a/0181a150098795a285256910005e6f0d?OpenDocument">http://service1.symantec.com/SUPPORT/nip.nsf/5a5e9c8a8ac2ec3c882568f60060f23a/0181a150098795a285256910005e6f0d?OpenDocument" target="_blank">Norton support site</a>.';
    error_log('[PHPFormMail] HTTP_REFERER not defined. Browser: ' . getenv('HTTP_USER_AGENT') . '; Client IP: ' . getenv('REMOTE_ADDR') . '; Request Method: ' . getenv('REQUEST_METHOD') . ';', 0);
    if ($bad_referer == '')
    $bad_referer = '2';
    else
    $bad_referer .= ',2';
    return false;
    }
    } else {
    $errors[] = '1|There are no referers defined. All submissions will be denied. Please read the manual section titled &quot;<a href="' . MANUAL . '#setting_up" target="_blank">Setting Up the PHPFormMail Script</a>&quot;.';
    error_log('[PHPFormMail] You have no referers defined. All submissions will be denied.', 0);
    if ($bad_referer == '')
    $bad_referer = '3';
    else
    $bad_referer .= ',3';
    return false;
    }
    }
    /****************************************************************
    * check_recipients() breaks up the recipents e-mail addresses *
    * and then crossrefrences the domains that are legal referers *
    * Function added in 1.3.1 *
    ****************************************************************/
    function check_recipients($valid_recipients, $recipient_list)
    {
    global $errors,$bad_referer;
    $recipients_ok = true;
    $recipient_list = explode(',', $recipient_list);
    while (list(,$recipient) = each($recipient_list)) {
    $recipient_domain = false;
    $recipient = trim($recipient);
    reset($valid_recipients);
    while ((list(,$stored_domain) = each($valid_recipients)) && ($recipient_domain == false)) {
    if (eregi('^[_\.a-z0-9-]*@' . $stored_domain . '$', $recipient))
    $recipient_domain = true;
    }
    if ($recipient_domain == false) {
    $recipients_ok = false;
    error_log('[PHPFormMail] Illegal Recipient: ' . $recipient . ' from ' . getenv('HTTP_REFERER'), 0);
    }
    }
    if (!$recipients_ok) {
    $errors[] = '1|You are trying to send mail to a domain that is not in the allowed recipients list. Please read the manual section titled &quot;<a href="' . MANUAL . '#setting_up" target="_blank">Setting Up the PHPFormMail Script</a>&quot;.';
    if ($bad_referer == '')
    $bad_referer = '4';
    else
    if (!strstr($bad_referer,'4'))
    $bad_referer .= ',4';
    }
    return $recipients_ok;
    }
    /****************************************************************
    * error() is our generic error function. *
    * When called, it checks for errors in the $errors array and *
    * depending on $form["missing_fields_redirect"] will either *
    * print out the errors by calling the function output_html() *
    * or it will redirect to the location specified in *
    * $form["missing_fields_redirect"]. *
    ****************************************************************/
    function error() {
    global $form, $natural_form, $errors;
    $args = '';
    if (isset($form['missing_fields_redirect'])){
    if(isset($form['redirect_values'])) {
    $args = compile_url_args($natural_form);
    header("Location: ". $form["missing_fields_redirect"] . $args);
    } else
    header('Location: ' . $form['missing_fields_redirect']);
    } else {
    if(!isset($form['title']))
    $form['title'] = 'PHPFormMail - Error';
    $output = "<div class=\"title\">The following errors were found/div>\n<ul>\n";
    $crit_error = 0;
    while (list(,$val) = each ($errors)) {
    list($crit,$message) = explode('|',$val);
    $output .= ' <li>' . $message . "</li>\n";
    if($crit == 1)
    $crit_error = 1;
    }
    $output .= "</ul>\n";
    if($crit_error == 1)
    $output .= "<div class=\"crit\">PHPFormMail has experienced errors that must be fixed by the webmaster. Mail will NOT be sent until these issues are resolved. Once these issues are resolved, you will have to resubmit your form to PHPFormMail for the mail to be sent.</div><div class=\"returnlink\">Please use the <a href=""\"javascript: history.back();\">back</a> button to return to the site.</div>\n";
    else
    $output .= "<div class=\"returnlink\">Please use the <a href=""\"javascript: history.back();\">back</a> button to correct these errors.</div>\n";
    output_html($output);
    }
    }
    /****************************************************************
    * cerror() is our error function for custom errors you wish *
    * tat are beyond the scope of the original script. *
    * When called, it checks for errors in the $errors array and *
    * depending on $form["custom_error_redirect"] will either *
    * print out the errors by calling the function output_html() *
    * or it will redirect to the location specified in *
    * $form["custom_error_redirect"]. *
    ****************************************************************/
    function cerror() {
    global $form, $natural_form, $errors;
    $args = '';
    if (isset($form['custom_error_redirect'])){
    if(isset($form['redirect_values'])) {
    # If you want to pass the form fields, uncomment the next two lines
    # and comment out the third line.
    if ($form["sessions"]) {
    compile_url_args($natural_form);
    compile_error_args($errors);
    } else {
    $args = compile_url_args($natural_form);
    $args .= "&" . compile_error_args($errors);
    }
    # $args = "?" . compile_error_args($errors);
    header("Location: ". $form["custom_error_redirect"] . $args);
    } else
    header('Location: ' . $form['custom_error_redirect']);
    } else {
    $form['title'] = 'PHPFormMail - Error';
    $output = "<p class=\"title\">The following errors were found/p>\n<ul>\n";
    $crit_error = 0;
    while (list(,$val) = each ($errors)) {
    list($crit,$message) = explode('|',$val);
    $output .= ' <li>' . $message . "</li>\n";
    if($crit == 1)
    $crit_error = 1;
    }
    $output .= "</ul>\n";
    if($crit_error == 1)
    $output .= "<p class=\"crit\">PHPFormMail has experienced errors that must be fixed by the webmaster. Mail will NOT be sent until these issues are resolved. Once these issues are resolved, you will have to resubmit your form to PHPFormMail for the mail to be sent.<p><p>Please use the <a href=""\"javascript: history.back();\">back</a> button to return to the site.</p>\n";
    else
    $output .= "<p>Please use the <a href=""\"javascript: history.back();\">back</a> button to correct these errors.</p>\n";
    output_html($output);
    }
    }
    /****************************************************************
    * compile_url_args() is used to create the arguments from *
    * $form for sending to the "Thank you" and redirected "Error" *
    * pages. This allows for the "Thank you/Error" pages to *
    * properly report errors and if needed, record the values to a *
    * different medium. *
    * Function added in 1.03.0 *
    ****************************************************************/
    function compile_url_args($form) {
    global $bad_referer, $bad_email, $bad_function, $invis_array, $in_array_func;
    global $HTTP_POST_FILES, $HTTP_SESSION_VARS;
    if ($form["sessions"]) {
    // form fields
    while(list($key,$val) = each($form)) {
    if (!$in_array_func($key,$invis_array)) {
    if(is_array($val)) {
    while(list($key1,$val1) = each($val))
    $HTTP_SESSION_VARS[$key1] = "[" . $val1 . "]";
    } else {
    $$key = $val;
    $HTTP_SESSION_VARS[$key] = $val;
    }
    }
    }
    // attachments file names
    if (isset($form['file_name'])) {
    $filenames = split(',', $form['file_name']);
    while(list(,$val) = each($filenames)) {
    $val = trim($val);
    global $$val;
    if ($HTTP_POST_FILES[$val]['size']) {
    $$val = $HTTP_POST_FILES[$val]['name'];
    $HTTP_SESSION_VARS[$val] = $$val;
    }
    }
    }
    // flags for bad referrer or bad email address
    $HTTP_SESSION_VARS['bad_referer'] = $bad_referer;
    $HTTP_SESSION_VARS['bad_email'] = $bad_email;
    $HTTP_SESSION_VARS['bad_function'] = $bad_function;
    } else {
    $output = "?";
    // form fields
    while(list($key,$val) = each($form)) {
    if (!$in_array_func($key,$invis_array)) {
    if (is_array($val)) {
    while(list($key1,$val1) = each($val))
    $output .= urlencode($key ."[" . $key1 . "]") . "=" . urlencode($val1) . "&";
    } else
    $output .= urlencode($key) . "=" . urlencode($val) . "&";
    }
    }
    // attachments file names
    if (isset($form['file_name'])) {
    $filenames = split(',', $form['file_name']);
    while(list(,$val) = each($filenames)) {
    $val = trim($val);
    global $$val;
    if ($HTTP_POST_FILES[$val]['size'])
    $output .= urlencode($val) . '=' . urlencode($HTTP_POST_FILES[$val]['name']) . "&";
    }
    }
    // flags for bad referrer or bad email address
    $output .= urlencode("bad_referer") . "=" . urlencode(stripslashes($bad_referer)) . "&";
    $output .= urlencode("bad_email") . "=" . urlencode(stripslashes($bad_email)) . "&";
    $output .= urlencode("bad_function") . "=" . urlencode(stripslashes($bad_function));
    }
    return $output;
    }
    /**************************************************************
    * compile_error_args() is used to append the arguments from *
    * $error for sending to the custom error redirect function *
    * page. This allows for the "Error" page to properly report *
    * the errors. Note that for your convenience, it also *
    * appends the number of errors as variable "numcerror" *
    **************************************************************/
    function compile_error_args($errors){
    global $form, $HTTP_SESSION_VARS;
    $errcount = 0;
    $errname = 'cerror';
    $numcerrstr = 'numcerror';
    if ($form["sessions"]) {
    $output = " ";
    while (list(,$val) = each ($errors)) {
    $errcount = $errcount + 1;
    $key = $errname . $errcount;
    // $$key = $val;
    $HTTP_SESSION_VARS[$key] = $val;
    }
    $HTTP_SESSION_VARS[$numcerrstr] = $errcount;
    } else {
    $output = '';
    while (list(,$val) = each ($errors)) {
    $errcount = $errcount + 1;
    $key = $errname . $errcount;
    $output .= urlencode($key) . "=" . urlencode($val) . "&";
    }
    $output .= urlencode($numcerrstr) . "=" . urlencode($errcount);
    }
    return $output;
    }
    /****************************************************************
    * check_required() is the function that checks all required *
    * fields to see if they are empty or match the provided regex *
    * string (regex checking added in 1.02.0). *
    * *
    * Should a required variable be empty or not match the regex *
    * pattern, a error will be added to the global $errors array. *
    ****************************************************************/
    function check_required() {
    global $form, $errors, $invis_array, $fieldname_lookup;
    global $HTTP_POST_FILES;
    if ((!isset($form['recipient'])) && (!isset($form['recipient_bcc']))) {
    $errors[] = '1|There is no recipient to send this mail to. Please read the manual section titled &quot;<a href="' . MANUAL . '#recipient" target="_blank">Form Configuration - Recipient</a>&quot;.';
    error_log('[PHPFormMail] There is no recipient defined from ' . getenv('HTTP_REFERER'), 0);
    }
    if (isset($form['required'])) {
    $required = split(',', $form['required']);
    while (list(,$val) = each($required)) {
    $val = trim($val);
    $regex_field_name = $val . '_regex';
    if ((!isset($form[$val])) || (isset($form[$val]) && (strlen($form[$val]) < 1))) {
    // if variable is a file upload, it will always be empty.
    // check if variable is file upload and apply proper test.
    $isfilename = false;
    if (isset($form['file_name'])) {
    $filenames = split(',', $form['file_name']);
    if (in_array($val,$filenames)) {
    $isfilename = true;
    }
    }
    if ($isfilename == true) {
    if (!$HTTP_POST_FILES[$val]['size']) {
    $errors[] = '0|Required value (<b>' . $val . '</b>) is missing.';
    }
    } else {
    if (isset($fieldname_lookup[$val]))
    $field = $fieldname_lookup[$val];
    else
    $field = $val;
    $errors[] = '0|Required value (<b>' . $field . '</b>) is missing.';
    }
    } else if (isset($form[$regex_field_name])) {
    if (!eregi($form[$regex_field_name],$form[$val])) {
    $errors[] = '0|Required value (<b>' . $fieldname_lookup[$val] . '</b>) has an invalid format.';
    }
    $invis_array[] = $regex_field_name;
    }
    }
    }
    }
    /***************************************************************
    * check_email() checks to see if an e-mail address is a valid *
    * e-mail address format. Validates whatever is in the field *
    * form["email_validate"]. *
    ***************************************************************/
    function check_email(){
    global $form, $errors, $invis_array, $bad_email;
    $problem = true;
    $valtype = '1';
    if ($form["email_validate"]) {
    if (isset($form["validation_type"])) {
    $valtype = $form["validation_type"];
    if (!($valtype == '1' or $valtype == '2'))
    $valtype = '1';
    }
    $addresses = split(',', $form['email_validate']);
    while(list(,$val) = each($addresses)) {
    $val = trim($val);
    if (!empty($form[$val])) {
    $validator = new email_validation_class;
    if ($valtype == "2") {
    $problem = $validator->ValidateEmailBox(trim($form[$val]));
    } else {
    $problem = $validator->ValidateEmailAddress(trim($form[$val]));
    }
    if (!$problem) {
    $errors[] = '0|' . trim($form[$val]) . ' is not a valid e-mail address; failed validation type: ' . $valtype;
    if (strlen($bad_email) > 0)
    $bad_email .= ',' . trim($form[$val]);
    else
    $bad_email = trim($form[$val]);
    }
    }
    }
    }
    return $problem;
    }
    /****************************************************************
    * sort_fields() is responsable for sorting all fields in $form *
    * depending $form["sort"]. *
    * There are three main sort methods: alphabetic, reverse *
    * alphabetic, and user supplied. *
    * *
    * The user supplied method is formatted "order:name,email,etc".*
    * The text "order" is required and the fields are comma *
    * sepperated. ("order" is legacy from the PERL version.) If *
    * the user supplied method leaves fields out of the comma *
    * sepperated list, the remaining fields will be appended to *
    * the end of the orderd list in the order they appear in the *
    * form. *
    * Function added in 1.02.0 *
    ****************************************************************/
    function sort_fields()
    {
    global $form;
    switch ($form["sort"]) {
    case 'alphabetic':
    case 'alpha': ksort($form);
    break;
    case 'ralphabetic':
    case 'ralpha': krsort($form);
    break;
    default: if ($col = strpos($form['sort'],':')) {
    $form['sort'] = substr($form['sort'],($col + 1));
    $temp_sort_arr = explode(',', $form['sort']);
    for($x = 0; $x < count($temp_sort_arr); $x++) {
    $out[$temp_sort_arr[$x]] = $form[$temp_sort_arr[$x]];
    unset($form[$temp_sort_arr[$x]]);
    }
    $form = array_merge($out,$form);
    }
    }
    return true;
    }

    /****************************************************************
    * alias_fields() creates a lookup array so we can use Aliases *
    * for the field names. If a alias is not available, the *
    * lookup array is filled with the form field's name *
    * Function added in 1.05.0 *
    ****************************************************************/
    function alias_fields()
    {
    global $form, $fieldname_lookup;
    while (list($key,) = each($form)) {
    $fieldname_lookup[$key] = $key;
    }
    reset($form);
    if (isset($form['alias'])) {
    $aliases = explode(',', $form['alias']);
    while (list(,$val) = each($aliases)) {
    $temp = explode('=', $val);
    $fieldname_lookup[trim($temp[0])] = trim($temp[1]);
    }
    }
    return true;
    }

    /****************************************************************
    * send_mail() the function that parses the data into SMTP *
    * format and sends the e-mail. *
    ****************************************************************/
    function send_mail(){
    global $form, $invis_array, $valid_env, $in_array_func, $errors, $bad_function, $HTTP_POST_FILES;
    $mail_status = false;
    $mail_html = false;
    $mailbody = '';
    $textbody = '';
    $realname = '';
    switch ($form['mail_newline']) {
    case 2: $mail_newline = "\r";
    break;
    case 3: $mail_newline = "\r\n";
    break;
    default:$mail_newline = "\n";
    }
    if (isset($form['gmt_offset']) && ereg('^({1}|(1{1}[0-2]{1}))$']\\-|\\+)?([0-9]{1}|(1{1}[0-2]{1}))$', $form['gmt_offset'])) {
    $mkseconds = mktime(gmdate('H') + $form['gmt_offset']);
    $mail_date = gmdate('F jS, Y', $mkseconds) . ' at ' . gmdate('h:iA', $mkseconds) . ' (GMT ' . $form['gmt_offset'] . ').';
    } else
    $mail_date = date('F jS, Y') . ' at ' . date('h:iA (T).');
    if (isset($form['html_mail']))
    if ($form['html_mail'])
    $mail_html = true;
    if (isset($form['custom_email_function']))
    if (function_exists($form['custom_email_function']))
    $mail_status = $form['custom_email_function']();
    else {
    $errors[] = '1|Your Custom email function, "' . $form['custom_email_function'] . '" ,does not exist.';
    $bad_function = trim($form['custom_email_function']);
    }
    else {
    if(isset($form['realname']))
    $realname = $form['realname'];
    elseif(isset($form['firstname']) || isset($form['lastname']))
    $realname = trim($form['firstname'] . ' ' . $form['lastname']);
    if ($mail_html)
    $mailbody = '<p><font size="3">Below is the result of your feedback form. It was submitted by ';
    $textbody = 'Below is the result of your feedback form. It was submitted by ' . $mail_newline;
    if(isset($realname)) {
    if ($mail_html)
    $mailbody.= $realname . ' (' . $form['email'] . ') on ' . $mail_date . '</font></p>';
    $textbody.= $realname . ' (' . $form['email'] . ') on ' . $mail_date . $mail_newline . $mail_newline;
    } else {
    if ($mail_html)
    $mailbody.= $form['email'] . ' on ' . $mail_date . '</font></p>';
    $textbody.= $form['email'] . ' on ' . $mail_date . $mail_newline . $mail_newline;
    }
    reset($form);
    while (list($key,$val) = each($form))
    if ((!$in_array_func($key,$invis_array)) && ((isset($form['print_blank_fields'])) || ($val))) {
    if ($mail_html)
    $mailbody .= '<b>' . $key . '</b>: ' . $val . '<br />';
    $textbody .= $key . ': ' . $val . $mail_newline;
    }
    if (isset($form['file_name'])) {
    $filenames = split(',', $form['file_name']);
    while(list(,$val) = each($filenames)) {
    $val = trim($val);
    global $$val;
    if ($HTTP_POST_FILES[$val]['size']) {
    if ($mail_html)
    $mailbody .= '<b>' . $val . '</b>: ' . $HTTP_POST_FILES[$val]['name'] . '<br />';
    $textbody .= $val . ': ' . $HTTP_POST_FILES[$val]['name'] . $mail_newline;
    }
    }
    }
    if (isset($form['env_report'])) {
    $temp_env_report = explode(',', $form['env_report']);
    if ($mail_html)
    $mailbody .= "<br /><br /><b>-------- Env Report --------</b><br />";
    $textbody .= $mail_newline . $mail_newline . "-------- Env Report --------" . $mail_newline;
    while(list(,$val) = each($temp_env_report))
    if($in_array_func($val,$valid_env)) {
    if ($mail_html)
    $mailbody .= '<b>' . $val . '</b>: ' . getenv($val) . '<br />';
    $textbody .= $val . ': ' . getenv($val) . $mail_newline;
    }
    }
    $mail = new phpmailer();
    $mail->From = $form["email"];
    $mail->AddAddress($form['recipient'], '');
    $mail->FromName = trim($realname);
    if (isset($form['subject']))
    $mail->Subject = trim($form['subject']);
    if(isset($form['recipient_cc']))
    $mail->AddCC($form['recipient_cc']);
    if(isset($form['recipient_bcc']))
    $mail->AddBCC($form['recipient_bcc']);
    if(isset($form['reply_to']))
    $mail->AddReplyTo($form['reply_to']);
    if(isset($form['priority']))
    $mail->Priority = $form['priority'];
    if (isset($form['file_name'])) {
    $filenames = split(',', $form['file_name']);
    while(list(,$val) = each($filenames)) {
    $val = trim($val);
    if ($HTTP_POST_FILES[$val]['size'])
    $mail->AddAttachment($$val,$HTTP_POST_FILES[$val]['name']);
    }
    }
    if ($mail_html) {
    $mail->Body = $mailbody;
    $mail->AltBody = $textbody;
    } else
    $mail->Body = $textbody;
    $mail_status = $mail->Send();
    }
    if(!$mail_status){
    $errors[] = '1|Message could not be sent due to an error while trying to send the mail.';
    error_log('[PHPFormMail] Mail could not be sent due to an error while trying to send the mail.');
    }
    return $mail_status;
    }
    /****************************************************************
    * output_html() is used to output all HTML to the browser. *
    * This function is called if there is an error or for the *
    * "Thank You" page if neither are declaired as redirects. *
    * *
    * While called output_html() it actually outputs valid XHTML *
    * 1.0 documents. *
    * Function added in 1.02.0 *
    ****************************************************************/
    function output_html($body)
    {
    global $form;
    print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
    print "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en-US\" lang=\"en-US\">\n";
    print "<head>\n";
    print " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=us-ascii\" />\n";
    print " <meta name=\"robots\" content=\"noindex,nofollow\" />\n";
    print " <title>" . $form["title"] . "</title>\n";
    print " <style type=\"text/css\">\n";
    print " BODY {" . $form['bgcolor'] . ' ' . $form['text_color'] . "}\n";
    if (isset($form['link_color']))
    print " A {" . $form['link_color'] . "}\n";
    if (isset($form['alink_color']))
    print " A:active {" . $form['alink_color'] . "}\n";
    if (isset($form['vlink_color']))
    print " A:visited {" . $form['vlink_color'] . "}\n";
    print " .title {font-size: 14pt; font-weight: bold; margin-bottom: 20pt}\n";
    print " .crit {font-size: 12pt; font-weight: bold; color: #F00; margin-bottom: 10pt;}\n";
    print " .returnlink {font-size: 12pt; margin-top: 20pt; margin-bottom: 20pt;}\n";
    print " .validbutton {margin-top: 20pt; margin-bottom: 20pt;}\n";
    print " </style>\n";
    if (isset($form['css']))
    print " <link rel=\"stylesheet\" href=""\"" . $form['css'] . "\">\n";
    print "</head>\n\n";
    print "<body>\n";
    print "<!-- PHPFormMail " . VERSION . " from http://www.boaddrink.com -->\n";
    print $body;
    print "<div class=\"validbutton\"><a href=""\"http://validator.w3.org/check/referer\" target=\"_blank\"><img src=""\"http://www.w3.org/Icons/valid-xhtml10\" style=\"border:0;width:88px;height:31px\" alt=\"Valid XHTML 1.0!\" /></a></div>\n";
    print "</body>\n";
    print "</html>";
    }
    $form = $natural_form = decode_vars();
    if ($form["sessions"])
    session_start();
    if (count($form) > 0) {
    $form['bgcolor'] = isset($form['bgcolor']) ? ('background-color: ' . $form['bgcolor'] . ';') : ('background-color: #FFF;');
    $form['text_color'] = isset($form['text_color']) ? ('color: ' . $form['text_color'] . ';') : ('color: #000;');
    $form['link_color'] = isset($form['link_color']) ? ('color: ' . $form['link_color'] . ';') : NULL;
    $form['alink_color'] = isset($form['alink_color']) ? ('color: ' . $form['alink_color'] . ';') : NULL;
    $form['vlink_color'] = isset($form['vlink_color']) ? ('color: ' . $form['vlink_color'] . ';') : NULL;
    // PFMA remove if block
    // Determine (based on the PHP version) if we should use the native
    // PHP4 in_array or the coded fake_in_array
    if (phpversion() >= '4.0.0')
    $in_array_func = 'in_array';
    else
    $in_array_func = 'fake_in_array';
    alias_fields();
    if(CHECK_REFERER == true)
    check_referer($referers);
    else
    error_log('[PHPFormMail] HTTP_REFERER checking is turned off. Referer: ' . getenv('HTTP_REFERER') . '; Client IP: ' . getenv('REMOTE_ADDR') . ';', 0);
    if (isset($form['recipient']))
    check_recipients($recipients, $form['recipient']);
    if (isset($form['recipient_cc']))
    check_recipients($recipients, $form['recipient_cc']);
    if (isset($form['recipient_bcc']))
    check_recipients($recipients, $form['recipient_bcc']);
    check_required();
    check_email();
    if (!$errors) {
    $process_form = true;
    if (isset($form["custom_error_function"])) {
    if (function_exists($form["custom_error_function"])) {
    $process_form = $form["custom_error_function"]();
    if (!$process_form) {
    cerror();
    exit;
    }
    } else {
    $errors[] = '1|Your Custom error function, "' . $form["custom_error_function"] . '" ,does not exist.';
    cerror();
    exit;
    }
    }
    if ($process_form) {
    if (!isset($form['subject']))
    $form['subject'] = 'WWW Form Submission';
    if (!isset($form['email']))
    $form['email'] = 'email@example.com';
    if (!isset($form['mail_newline']))
    $form['mail_newline'] = 1;
    if (isset($form['sort']))
    sort_fields();
    if (isset($form['hidden'])) {
    // PFMA REMOVE 1
    $form['hidden'] = str_replace(' ', '', $form['hidden']);
    $form['hidden'] = explode(',', $form['hidden']);
    // PFMA ADD $form['hidden'] = array_map('trim', $form['hidden']);
    }
    if (send_mail()) {
    if (isset($form['redirect'])){
    if(isset($form['redirect_values'])) {
    $args = compile_url_args($natural_form);
    Header('Location: '. $form["redirect"] . $args);
    } else
    header('Location: ' . $form['redirect']);
    } else {
    if (!isset($form['title']))
    $form['title'] = 'PHPFormMail - Form Results';
    $output = "<div class=\"title\">The following information has been submitted/div>\n";
    reset($form);
    while (list($key,$val) = each($form)) {
    if ((!$in_array_func($key,$invis_array)) && ((isset($form['print_blank_fields'])) || ($val)))
    if ((isset($form['hidden'])) && ($in_array_func($key,$form['hidden'])))
    $output .= '<div class="field"><b>' . htmlspecialchars($fieldname_lookup[$key]) . "/b> <i>(hidden)</i></div>\n";
    else
    $output .= '<div class="field"><b>' . htmlspecialchars($fieldname_lookup[$key]) . '/b> ' . htmlspecialchars($val) . "</div>\n";
    }
    if (isset($form['file_name'])) {
    $filenames = split(',', $form['file_name']);
    while(list(,$val) = each($filenames)) {
    $val = trim($val);
    if ($HTTP_POST_FILES[$val]['size'])
    $output .= '<b>' . htmlspecialchars($val) . '/b> ' . htmlspecialchars($HTTP_POST_FILES[$val]['name']) . "<br />\n";
    }
    }
    if (isset($form['return_link_url']) && isset($form['return_link_title']))
    $output .= '<div class="returnlink"><a href="' . $form["return_link_url"] . '">'. $form["return_link_title"] . "</a></div>\n";
    output_html($output);
    }
    }
    }
    }
    } else {
    $errors[] = '0|Nothing was sent by a form. (No data was sent by POST or GET method.) There is nothing to process here.';
    error_log('[PHPFormMail] No data sent by POST or GET method. (' . getenv('HTTP_REFERER') . ')', 0);
    }
    if (count($errors) > 0)
    error();
    ?>
    Herman Drost
    http://www.isitebuild.com
    Affordable Web Site Design
    and Web Site Hosting

  4. #4
    SitePoint Addict seanmayhew's Avatar
    Join Date
    Aug 2002
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My guess is two or more of these includes are sending out header information after the headers have already been sent and the first line of html has been run.
    PHP Code:
    include('function.decodevars.php');
    /****************************************************************************
    * Class for sending e-mails. Supports attachments and HTML. (required) *
    ****************************************************************************/
    include('class.phpmailer.php');
    /****************************************************************************
    * Class for validating e-mail address. (required) *
    ****************************************************************************/
    include('email_validation.php');
    /**************************************************************************** 
    It says line 824 so It must be happening inside one of these three includes because the length of your entire document is only 774 lines. Probably the email_validation.php

  5. #5
    SitePoint Evangelist
    Join Date
    Jan 2001
    Posts
    478
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I really appreciate your help (I'm not a PHP coder)

    Here's the email_vailidation script

    <?
    /*
    * email_validation.php
    *
    * @(#) $Header: /home/mlemos/cvsroot/PHPlibrary/email_validation.php,v 1.18 2002/09/06 01:05:52 mlemos Exp $
    *
    */
    class email_validation_class
    {
    var $email_regular_expression="^([-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,6}\$";
    var $timeout=0;
    var $localhost="";
    var $localuser="";
    var $debug=0;
    var $html_debug=0;
    var $exclude_address="";
    var $getmxrr="GetMXRR";
    var $next_token="";
    Function Tokenize($string,$separator="")
    {
    if(!strcmp($separator,""))
    {
    $separator=$string;
    $string=$this->next_token;
    }
    for($character=0;$character<strlen($separator);$character++)
    {
    if(GetType($position=strpos($string,$separator[$character]))=="integer")
    $found=(IsSet($found) ? min($found,$position) : $position);
    }
    if(IsSet($found))
    {
    $this->next_token=substr($string,$found+1);
    return(substr($string,0,$found));
    }
    else
    {
    $this->next_token="";
    return($string);
    }
    }
    Function OutputDebug($message)
    {
    $message.="\n";
    if($this->html_debug)
    $message=str_replace("\n","<br />\n",HtmlEntities($message));
    echo $message;
    flush();
    }
    Function GetLine($connection)
    {
    for($line="";
    {
    if(feof($connection))
    return(0);
    $line.=fgets($connection,100);
    $length=strlen($line);
    if($length>=2
    && substr($line,$length-2,2)=="\r\n")
    {
    $line=substr($line,0,$length-2);
    if($this->debug)
    $this->OutputDebug("S $line");
    return($line);
    }
    }
    }
    Function PutLine($connection,$line)
    {
    if($this->debug)
    $this->OutputDebug("C $line");
    return(fputs($connection,"$line\r\n"));
    }
    Function ValidateEmailAddress($email)
    {
    return(eregi($this->email_regular_expression,$email)!=0);
    }
    Function ValidateEmailHost($email,&$hosts)
    {
    if(!$this->ValidateEmailAddress($email))
    return(0);
    $user=$this->Tokenize($email,"@");
    $domain=$this->Tokenize("");
    $hosts=$weights=array();
    $getmxrr=$this->getmxrr;
    if(function_exists($getmxrr)
    && $getmxrr($domain,$hosts,$weights))
    {
    $mxhosts=array();
    for($host=0;$host<count($hosts);$host++)
    $mxhosts[$weights[$host]]=$hosts[$host];
    KSort($mxhosts);
    for(Reset($mxhosts),$host=0;$host<count($mxhosts);Next($mxhosts),$host++)
    $hosts[$host]=$mxhosts[Key($mxhosts)];
    }
    else
    {
    if(strcmp($ip=@gethostbyname($domain),$domain)
    && (strlen($this->exclude_address)==0
    || strcmp(@gethostbyname($this->exclude_address),$ip)))
    $hosts[]=$domain;
    }
    return(count($hosts)!=0);
    }
    Function VerifyResultLines($connection,$code)
    {
    while(($line=$this->GetLine($connection)))
    {
    if(!strcmp($this->Tokenize($line," "),$code))
    return(1);
    if(strcmp($this->Tokenize($line,"-"),$code))
    return(0);
    }
    return(-1);
    }
    Function ValidateEmailBox($email)
    {
    if(!$this->ValidateEmailHost($email,$hosts))
    return(0);
    if(!strcmp($localhost=$this->localhost,"")
    && !strcmp($localhost=getenv("SERVER_NAME"),"")
    && !strcmp($localhost=getenv("HOST"),""))
    $localhost="localhost";
    if(!strcmp($localuser=$this->localuser,"")
    && !strcmp($localuser=getenv("USERNAME"),"")
    && !strcmp($localuser=getenv("USER"),""))
    $localuser="root";
    for($host=0;$host<count($hosts);$host++)
    {
    $domain=$hosts[$host];
    if(ereg('^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$',$domain))
    $ip=$domain;
    else
    {
    if($this->debug)
    $this->OutputDebug("Resolving host name \"".$hosts[$host]."\"...");
    if(!strcmp($ip=@gethostbyname($domain),$domain))
    {
    $this->OutputDebug("Could not resolve host name \"".$hosts[$host]."\".");
    continue;
    }
    }
    if(strlen($this->exclude_address)
    && !strcmp(@gethostbyname($this->exclude_address),$ip))
    {
    $this->OutputDebug("Host address of \"".$hosts[$host]."\" is the exclude address");
    continue;
    }
    if($this->debug)
    $this->OutputDebug("Connecting to host address \"".$ip."\"...");
    if(($connection=($this->timeout ? @fsockopen($ip,25,$errno,$error,$this->timeout) : @fsockopen($ip,25))))
    {
    if($this->debug)
    $this->OutputDebug("Connected.");
    if($this->VerifyResultLines($connection,"220")>0
    && $this->PutLine($connection,"HELO $localhost")
    && $this->VerifyResultLines($connection,"250")>0
    && $this->PutLine($connection,"MAIL FROM: <$localuser@$localhost>")
    && $this->VerifyResultLines($connection,"250")>0
    && $this->PutLine($connection,"RCPT TO: <$email>")
    && ($result=$this->VerifyResultLines($connection,"250"))>=0)
    {
    if($this->debug)
    $this->OutputDebug("This host states that the address is ".($result ? "" : "not ")."valid.");
    fclose($connection);
    if($this->debug)
    $this->OutputDebug("Disconnected.");
    return($result);
    }
    if($this->debug)
    $this->OutputDebug("Unable to validate the address with this host.");
    fclose($connection);
    if($this->debug)
    $this->OutputDebug("Disconnected.");
    }
    else
    {
    if($this->debug)
    $this->OutputDebug("Failed.");
    }
    }
    return(-1);
    }
    };
    ?>
    Herman Drost
    http://www.isitebuild.com
    Affordable Web Site Design
    and Web Site Hosting


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •