Conversion to PHP5 | Newbie | | Join Date: Jul 2008
Posts: 2
| |
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. - <?php
-
-
// email adres waarnaar het formulier wordt gestuurd //////////////////////////////////////////
-
// als deze waarde niet is ingevuld, wordt het send_to veld gebruikt
-
$send_to = "Cartexpo.nl <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_fields = '*' - betekent alle velden
-
// $database_fields = array('from', 'subject') - alleen 'from' en 'subject' velden
-
$database_fields = '*';
-
-
////// 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 = "Bevestiging 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:info@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_enabled;
-
$form = get_form_data();
-
$errors = check_form($form);
-
if ($errors) {
-
display_errors($errors);
-
return;
-
}
-
send_mail($form);
-
if ($autoresponder_enabled)
-
auto_respond($form);
-
if ($database_enabled)
-
save_form($form);
-
redirect();
-
}
-
-
function redirect(){
-
global $redirect_url;
-
header("Location: $redirect_url");
-
exit();
-
}
-
-
-
function save_form($vars){
-
global $database_file, $database_fields;
-
$f = fopen($database_file, 'a');
-
if (!$f){
-
die("Cannot open db file for save");
-
}
-
foreach ($vars as $k=>$v) {
-
$vars[$k] = str_replace(array("|", "\r","\n"), array('_',' ',' '), $v);
-
}
-
if (is_array($database_fields)) {
-
$vars_orig = $vars;
-
$vars = array();
-
foreach ($database_fields as $k)
-
$vars[$k] = $vars_orig[$k];
-
}
-
$str = join('|', $vars);
-
fwrite($f, $str."\n");
-
fclose($f);
-
}
-
-
function auto_respond($vars){
-
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|reqnum)$/', '', $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_enabled;
-
global $REMOTE_ADDR;
-
global $klanttekst;
-
global $tabelstop;
-
global $totalekosten;
-
global $transporttekst;
-
global $send_to;
-
global $autoresponder_from;
-
global $onderwerp;
-
-
-
global $HTTP_POST_FILES;
-
$files = array(); //files (field names) to attach in mail
-
if (count($HTTP_POST_FILES) && $attachment_enabled){
-
$files = array_keys($HTTP_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<BR>
-
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:$emailklant">$emailklant
-
-
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\nContent-Type: multipart/mixed;\n boundary=\"$mime_delimiter\"\r\nContent-Disposition: inline");
-
-
foreach ($send_cc as $v){
-
mail($v, $_subject, $mail,
-
"Mime-Version: 1.0\r\nFrom: $_send_from\r\nContent-Type: multipart/mixed;\n boundary=\"$mime_delimiter\"\r\nContent-Disposition: inline");
-
}
-
-
}
-
-
function get_form_data(){
-
global $REQUEST_METHOD;
-
global $HTTP_POST_VARS;
-
global $HTTP_GET_VARS;
-
-
$vars = ($REQUEST_METHOD == '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($vars){
-
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>Postcode veld is leeg";
-
}
-
if (!$plaats){
-
$errors[6] = "<b>Plaats veld is leeg";
-
}
-
if (!$telefoon){
-
$errors[7] = "<b>Telefoon nummer veld is leeg";
-
}
-
if (!$bedrijfsnaam){
-
$errors[8] = "<b>Bedrijfsnaam 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>Ontvangende email adres leeg (check configuratie)";
-
} else if (!strlen($send_to) && !check_email($vars['email_to'])){
-
//if to email specified in form, check it and display error
-
$errors[] = "<b>Ontvangende email adres incorrect";
-
}
-
if (!strlen($vars['subject']) && !strlen($subject)){
-
$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_name leeg";
-
}
-
-
-
-
-
-
-
if (preg_match('/^(.+?)_req$/i', $k, $m) && !strlen($v)){
-
$field_name = ucfirst($m[1]);
-
$errors[] = "Required field <b>$field_name leeg";
-
}
-
if (preg_match('/^(.+?)_req$/i', $k, $m) && !strlen($v)){
-
$field_name = ucfirst($m[1]);
-
$errors[] = "Required field <b>$field_name leeg";
-
}
-
if (preg_match('/^(.+?)_req$/i', $k, $m) && !strlen($v)){
-
$field_name = ucfirst($m[1]);
-
$errors[] = "Required field <b>$field_name 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_name 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_name must contain digits and only digits";
-
}
-
}
-
-
-
return $errors;
-
}
-
-
function display_errors($errors){
-
$errors = '<li>' . join('<li>', $errors);
-
print <<
-
<html>
-
<head>
-
<title>TopEmaille.nl
-
<link rel="stylesheet" type="text/css" href="bestelformulier.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="javascript: 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($email) {
-
#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();
-
?>
-
I hope some one can help me with this.
Greetzzzz
Leendert
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | re: Conversion to PHP5
There's no way I, nor others, will be able to read that.
Please use code tags when posting code in the forums.
| | Newbie | | Join Date: Jul 2008
Posts: 2
| | | re: Conversion to PHP5 Quote:
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
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | re: Conversion to PHP5
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.
|  | Moderator | | Join Date: Nov 2006 Location: Iceland
Posts: 3,745
| | | re: Conversion to PHP5
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.
| | Needs Regular Fix | | Join Date: Mar 2008
Posts: 311
| | | re: Conversion to PHP5
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.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,327 network members.
|