Conversion to PHP5

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • The Big One
    New Member
    • Jul 2008
    • 2

    Conversion to PHP5

    8-7-2008

    Hello,

    Our hosting provider has changed his server to PHP5.
    I have a PHP file that normaly gives the custumor an email, and i get one mail.
    Now the server has changed i only get my email, but the custumor gets nothing.

    Who can help me to change this PHP file to PHP5 ?????

    Here is the file concept.

    [CODE=php] <?php

    // email adres waarnaar het formulier wordt gestuurd //////////////////////////////////////////
    // als deze waarde niet is ingevuld, wordt het send_to veld gebruikt
    $send_to = "Cartexpo.n l <info@cartexpo. nl>";

    // variabele $send_cc voor een kopie naar een ander e-mailadres (niet de auto-reply)
    // bijvoorbeeld: $send_cc = array('vriend1@ ccc.cc', 'vriend2@ccc.cc ');
    //
    $send_cc = array();

    // Onderwerp. Als dit leeg is wordt de waarde gebruikt die in het formulier is aangegeven
    $subject = "";

    // Toegestane referrers (wie dit bestand mag gebruiken, meerdere waarden mogelijk)
    $referrers = array('cartexpo .nl');


    // Te verzamelen velden
    // $database_field s = '*' - betekent alle velden
    // $database_field s = array('from', 'subject') - alleen 'from' en 'subject' velden
    $database_field s = '*';

    ////// Redirect URL (waar de bezoeker uitkomt na verzenden)
    $redirect_url = 'bedankt.html';

    ////// Automatisch antwoord
    ////// In het antwoord kun je variabelen op de volgende manier meegeven
    ////// %veld_naam% in de antwoord tekst.
    //////

    $autoresponder_ enabled = 0;
    $autoresponder_ from = $send_to;
    $autoresponder_ subject = "Bevestigin g van informatie aanvraag cartexpo";

    $headers = "From: $send_to\r\n";
    $headers .= "Content-type: text/html\r\n";





    ////// De velden uit het formulier omzetten in PHP variabelen



    $voornaam = $_POST['voornaam'];
    $achternaam = $_POST['achternaam'];
    $geslacht = $_POST['geslacht'];
    $volledigenaam = "$voornaam $achternaam";
    $postcode = $_POST['postcode'];


    if ($extra_info <> "") {
    $extra_info = "Uw vraag/opmerking:<BR>" ;
    $extra_info .= $_POST['extra_info'];
    } else {
    $extra_info = "";
    }



    $autoresponder_ message = <<


    <FONT font face="Arial, Helvetica, sans-serif">

    Geachte $geslacht $achternaam,<BR >


    Bedankt voor uw informatie aanvraag betreffende het dealerschap van cartexpo<sup>®.

    U heeft voor de volgende emaille producten informatie aangevraagd:<BR >


    $onderwerp<BR>


    $extra_info<BR>


    Om uw aanvraag effectief en snel te beantwoorden verzoeken wij U om de volgende informatie aan ons door te geven:<BR>


    <li> Locatie (b.v. winkelcentrum / A, B locatie / industrie terrein).

    <li> Bedrijfsgrootte (aantal medewerkers).

    <li> Welke naamplaten heeft u reeds in het assortiment (leveranciers + product)

    <li> Al ervaring met emaille producten ja / nee.

    <BR>
    U kunt deze informatie rechtstreeks mailen naar <a href="mailto:in fo@cartexpo.nl" >info@cartexpo. nl

    <BR>
    Voor vragen kunt u ons telefonisch bereiken onder tel. nr. 0297-524040<BR>
    (ma t/m. vr. van 9.00-18.00 uur.)<BR>
    <BR>

    <BR>


    Met vriendelijke groet,<BR>





    Het cartexpo.nk<sup >® Team






    cartexpo.nl<sup >®

    Ondernemingsweg 1<BR>
    1422 DZ Uithoorn<BR>
    Tel.: 0297-524040<BR>
    Fax: 0297-524042<BR>



    </FONT>

    MSG;



    /*************** *************** *************** *************** ***************/

    function do_formmail(){
    global $autoresponder_ enabled, $database_enabl ed;
    $form = get_form_data() ;
    $errors = check_form($for m);
    if ($errors) {
    display_errors( $errors);
    return;
    }
    send_mail($form );
    if ($autoresponder _enabled)
    auto_respond($f orm);
    if ($database_enab led)
    save_form($form );
    redirect();
    }

    function redirect(){
    global $redirect_url;
    header("Locatio n: $redirect_url") ;
    exit();
    }


    function save_form($vars ){
    global $database_file, $database_field s;
    $f = fopen($database _file, 'a');
    if (!$f){
    die("Cannot open db file for save");
    }
    foreach ($vars as $k=>$v) {
    $vars[$k] = str_replace(arr ay("|", "\r","\n"), array('_',' ',' '), $v);
    }
    if (is_array($data base_fields)) {
    $vars_orig = $vars;
    $vars = array();
    foreach ($database_fiel ds as $k)
    $vars[$k] = $vars_orig[$k];
    }
    $str = join('|', $vars);
    fwrite($f, $str."\n");
    fclose($f);
    }

    function auto_respond($v ars){
    global $autoresponder_ from, $autoresponder_ message, $autoresponder_ subject, $headers;

    /// replace all vars in message
    $msg = $autoresponder_ message;
    preg_match_all( '/%(.+?)%/', $msg, $out);
    $s_vars = $out[1]; //field list to substitute
    foreach ($s_vars as $k)
    $msg = str_replace("%$ k%", $vars[$k], $msg);
    /// replace all vars in subject
    $subj = $autoresponder_ subject;
    preg_match_all( '/%(.+?)%/', $subj, $out);
    $s_vars = $out[1]; //field list to substitute
    foreach ($s_vars as $k)
    $subj = str_replace("%$ k%", $vars[$k], $subj);
    //
    $space = " ";
    $name = $vars[voornaam] . $space . $vars[achternaam];
    $_send_to = "$name <".$vars[email_from].">";
    $_send_from = $autoresponder_ from;
    mail($_send_to, $subj, $msg, "$headers") ;
    }

    function _build_fields($ vars){
    $skip_fields = array(
    'name_from',
    'email_from',
    'email_to',
    'name_to',
    'subject');
    // order by numeric begin, if it exists
    $is_ordered = 0;
    foreach ($vars as $k=>$v)
    if (in_array($k, $skip_fields)) unset($vars[$k]);

    $new_vars = array();
    foreach ($vars as $k=>$v){
    // remove _num, _reqnum, _req from end of field names
    $k = preg_replace('/_(req|num|reqnu m)$/', '', $k);
    // check if the fields is ordered
    if (preg_match('/^\d+[ \:_-]/', $k)) $is_ordered++;
    //remove number from begin of fields
    $k = preg_replace('/^\d+[ \:_-]/', '', $k);
    $new_vars[$k] = $v;
    }
    $vars = $new_vars;

    $max_length = 10; // max length of key field
    foreach ($vars as $k=>$v) {
    $klen = strlen($k);
    if (($klen > $max_length) && ($klen < 40))
    $max_length = $klen;
    }

    if ($is_ordered)
    ksort($vars);

    // make output text
    $out = "";
    foreach ($vars as $k=>$v){
    $k = str_replace('_' , ' ', $k);
    $k = ucfirst($k);
    $len_diff = $max_length - strlen($k);
    if ($len_diff > 0)
    $fill = str_repeat('.', $len_diff);
    else
    $fill = '';
    $out .= $k."$fill...: $v\n";
    }
    return $out;
    }


    function send_mail($vars ){
    global $send_to, $send_cc;
    global $subject;
    global $attachment_ena bled;
    global $REMOTE_ADDR;
    global $klanttekst;
    global $tabelstop;
    global $totalekosten;
    global $transporttekst ;
    global $send_to;
    global $autoresponder_ from;
    global $onderwerp;


    global $HTTP_POST_FILE S;
    $files = array(); //files (field names) to attach in mail
    if (count($HTTP_PO ST_FILES) && $attachment_ena bled){
    $files = array_keys($HTT P_POST_FILES);
    }

    // build mail
    $date_time = date('Y-m-d H:i:s');
    $mime_delimiter = md5(time());
    $fields = _build_fields($ vars);


    $bedrijfsnaam = $_POST['bedrijfsnaam'];
    $geslacht = $_POST['geslacht'];
    $voornaam = $_POST['voornaam'];
    $achternaam = $_POST['achternaam'];
    $adres = $_POST['adres'];
    $postcode = $_POST['postcode'];
    $plaats = $_POST['plaats'];
    $land = $_POST['land'];
    $telefoon = $_POST['telefoon'];
    $fax = $_POST['fax'];
    $emailklant = $_POST['email_from'];
    $website = $_POST['website'];
    $extra_info = $_POST['extra_info'];



    global $autoresponder_ message;

    $mail = <<
    This is a MIME-encapsulated message
    --$mime_delimiter
    Content-type: text/html
    Content-Transfer-Encoding: 8bit

    <STYLE TYPE='text/css'> BODY { font-size: 12px } TD { font-size: 12px } P { font-size: 12pt } { font-size: 90% }

    <CENTER>Cartexpo.nl - informatie formulier




    <FONT font face="Arial, Helvetica, sans-serif">


    $geslacht $achternaam wil meer informatie over:<BR>


    $extra_info<BR>




    </FONT>




    <B>Gegevens $geslacht $achternaam



    Bedrijfsnaam: $bedrijfsnaam<B R>
    Voornaam: $voornaam<BR>
    Achternaam: $achternaam<BR>


    Adres: $adres<BR>
    Postcode: $postcode<BR>
    Plaats: $plaats<BR>
    Land: $land<BR>
    Telefoon: $telefoon<BR>
    Fax: $fax<BR>
    E-mail: <a href="mailto:$e mailklant">$ema ilklant

    Website: <a href="$website" >$website







    EOF;



    //send to
    $_send_to = $send_to ? $send_to : "$vars[name_to] <".$vars[email_to].">";
    $space = " ";
    $name = $vars[voornaam] . $space . $vars[achternaam];
    $_send_from = "$name <".$vars[email_from].">";
    $_subject = $subject ? $subject : $vars['subject'];

    mail($_send_to, $_subject, $mail,
    "Mime-Version: 1.0\r\nFrom: $_send_from\r\n Content-Type: multipart/mixed;\n boundary=\"$mim e_delimiter\"\r \nContent-Disposition: inline");

    foreach ($send_cc as $v){
    mail($v, $_subject, $mail,
    "Mime-Version: 1.0\r\nFrom: $_send_from\r\n Content-Type: multipart/mixed;\n boundary=\"$mim e_delimiter\"\r \nContent-Disposition: inline");
    }

    }

    function get_form_data() {
    global $REQUEST_METHOD ;
    global $HTTP_POST_VARS ;
    global $HTTP_GET_VARS;

    $vars = ($REQUEST_METHO D == 'GET') ? $HTTP_GET_VARS : $HTTP_POST_VARS ;
    //strip spaces from all fields
    foreach ($vars as $k=>$v) $vars[$k] = trim($v);
    return $vars;
    }

    function check_form($var s){
    global $referrers;
    global $send_to;
    global $subject;
    global $HTTP_REFERER;

    $bedrijfsnaam = $_POST['bedrijfsnaam'];
    $geslacht = $_POST['geslacht'];
    $voornaam = $_POST['voornaam'];
    $achternaam = $_POST['achternaam'];
    $adres = $_POST['adres'];
    $postcode = $_POST['postcode'];
    $plaats = $_POST['plaats'];
    $land = $_POST['land'];
    $telefoon = $_POST['telefoon'];
    $fax = $_POST['fax'];
    $emailklant = $_POST['email_from'];
    $website = $_POST['website'];


    $errors = array();


    if (!$geslacht){
    $errors[1] = "<b>Heer/Mevrouw is niet gekozen";
    }
    if (!$adres){
    $errors[4] = "<b>Adres veld is leeg";
    }
    if (!$postcode){
    $errors[5] = "<b>Postcod e veld is leeg";
    }
    if (!$plaats){
    $errors[6] = "<b>Plaats veld is leeg";
    }
    if (!$telefoon){
    $errors[7] = "<b>Telefoo n nummer veld is leeg";
    }
    if (!$bedrijfsnaam ){
    $errors[8] = "<b>Bedrijfsnaa m veld is leeg";
    }

    // check from email set
    if (!strlen($vars['email_from'])){
    $errors[] = "<b>Email adres veld is fout/niet ingevuld";
    } else if (!check_email($ vars['email_from'])){
    $errors[] = "<b>Email adres veld is leeg/incorrect";
    }
    if (!strlen($send_ to) && !strlen($vars['email_to'])){
    $errors[] = "<b>Ontvang ende email adres leeg (check configuratie)";
    } else if (!strlen($send_ to) && !check_email($v ars['email_to'])){
    //if to email specified in form, check it and display error
    $errors[] = "<b>Ontvang ende email adres incorrect";
    }
    if (!strlen($vars['subject']) && !strlen($subjec t)){
    $errors[] = "<b>Subject leeg (check configuratie)";
    }
    foreach ($vars as $k=>$v){
    // check for required fields (end with _req)
    if (preg_match('/^(.+?)_req$/i', $k, $m) && !strlen($v)){
    $field_name = ucfirst($m[1]);
    $errors[] = "Required field <b>$field_nam e leeg";
    }






    if (preg_match('/^(.+?)_req$/i', $k, $m) && !strlen($v)){
    $field_name = ucfirst($m[1]);
    $errors[] = "Required field <b>$field_nam e leeg";
    }
    if (preg_match('/^(.+?)_req$/i', $k, $m) && !strlen($v)){
    $field_name = ucfirst($m[1]);
    $errors[] = "Required field <b>$field_nam e leeg";
    }
    if (preg_match('/^(.+?)_req$/i', $k, $m) && !strlen($v)){
    $field_name = ucfirst($m[1]);
    $errors[] = "Required field <b>$field_nam e leeg";
    }
    // check for number fields (end with _num)
    if (preg_match('/^(.+?)_num$/i', $k, $m) && strlen($v) && !is_numeric($v) ){
    $field_name = ucfirst($m[1]);
    $errors[] = "Field <b>$field_nam e must contain only digits or be leeg";
    }
    // check for number & required fields (end with _reqnum)
    if (preg_match('/^(.+?)_reqnum$/i', $k, $m) && !is_numeric($v) ){
    $field_name = ucfirst($m[1]);
    $errors[] = "Field <b>$field_nam e must contain digits and only digits";
    }
    }


    return $errors;
    }

    function display_errors( $errors){
    $errors = '<li>' . join('<li>', $errors);
    print <<
    <html>
    <head>
    <title>TopEmail le.nl
    <link rel="stylesheet " type="text/css" href="bestelfor mulier.css">
    </head>

    <body bgcolor=white>
    <h3 align=center>[color=red]Er is een fout opgetreden[/color]
    <hr width=80%>
    <table align=center>
    $errors
    </td>
    <p align=center>
    Vul de velden correct in s.v.p.<BR>

    <a href="javascrip t: history.back(-1)">< Terug
    </p>
    <hr width=80%>
    <center>
    <font size=2>cartexpo.nl ©, 2005
    </center>
    </body>
    EOF;
    }


    /**
    * Check email using regexes
    * @param string email
    * @return bool true if email valid, false if not
    */
    function check_email($em ail) {
    #characters allowed on name: 0-9a-Z-._ on host: 0-9a-Z-. on between: @
    if (!preg_match('/^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$/', $email))
    return false;

    #must start or end with alpha or num
    if ( preg_match('/^[^0-9a-zA-Z]|[^0-9a-zA-Z]$/', $email))
    return false;

    #name must end with alpha or num
    if (!preg_match('/([0-9a-zA-Z_]{1})\@./',$email) )
    return false;

    #host must start with alpha or num
    if (!preg_match('/.\@([0-9a-zA-Z_]{1})/',$email) )
    return false;

    #pair .- or -. or -- or .. not allowed
    if ( preg_match('/.\.\-.|.\-\..|.\.\..|.\-\-./',$email) )
    return false;

    #pair ._ or -_ or _. or _- or __ not allowed
    if ( preg_match('/.\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_./',$email) )
    return false;

    #host must end with '.' plus 2-5 alpha for TopLevelDomain
    if (!preg_match('/\.([a-zA-Z]{2,5})$/',$email) )
    return false;

    return true;
    }

    do_formmail();
    ?>
    [/CODE]

    I hope some one can help me with this.

    Greetzzzz

    Leendert
    Last edited by r035198x; Jul 8 '08, 02:00 PM. Reason: added code tags
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    There's no way I, nor others, will be able to read that.

    Please use code tags when posting code in the forums.

    Comment

    • The Big One
      New Member
      • Jul 2008
      • 2

      #3
      Originally posted by markusn00b
      There's no way I, nor others, will be able to read that.

      Please use code tags when posting code in the forums.
      Is it possible that i send you the file??

      Leendert

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        550 lines of code!

        Unfortunately it is time for me to leave for holiday!

        In the nick-of-time, too.

        Hopefully someone else will be able to help with that hefty code.

        Kind regards.

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Hi.

          Try the tips in this thread and see if you get any error messages.

          A quick look at your code tells me you will probably get a few warnings and notices.

          Try to solve them and post back if you run into any problems.

          Comment

          • coolsti
            Contributor
            • Mar 2008
            • 310

            #6
            I would say just try it.

            I migrated an entire database application that I developed over the past years for my company from PHP 4.x to PHP 4.x recently, and I didn't have to change any lines of code at all.

            I did get a large amount of warnings about depreciated syntax and other syntax that did not meet with the PHP5 standards, but the code works as it did before.

            Comment

            Working...