mám na stránkách možnost poslat mi email.
nějakej čas to fungovalo bez problémů, ale teď po odeslání prohlížeč vypisuje chybu:
Warning: Cannot modify header information - headers already sent by (output started at /www/doc/www.blabla.eu/www/Kontakt.php:1) in /www/doc/www.blabla.eu/www/Kontakt.php on line 82
mail se odešle, ale místo aby se znovu načetla stránka Kontakt.php, jak je ve scriptu, tak se vypíše ta hláška.
tady je code cely stránky, změnil jsem jen osobní údaje.
- Kód: Vybrat vše
<?php
function ValidateEmail($email)
{
$pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i';
return preg_match($pattern, $email);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['formid']) && $_POST['formid'] == 'fzprava')
{
$mailto = 'dyzons@gmail.com';
$mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;
$subject = 'Website form';
$message = 'Mujweb - nová zpráva.';
$success_url = './Kontakt.php';
$error_url = './Oooops.html';
$error = '';
$eol = "\n";
$boundary = md5(uniqid(time()));
$header = 'From: '.$mailfrom.$eol;
$header .= 'Reply-To: '.$mailfrom.$eol;
$header .= 'MIME-Version: 1.0'.$eol;
$header .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"'.$eol;
$header .= 'X-Mailer: PHP v'.phpversion().$eol;
if (!ValidateEmail($mailfrom))
{
$error .= "The specified email address is invalid!\n<br>";
}
if (!empty($error))
{
$errorcode = file_get_contents($error_url);
$replace = "##error##";
$errorcode = str_replace($replace, $error, $errorcode);
echo $errorcode;
exit;
}
$internalfields = array ("submit", "reset", "send", "filesize", "formid", "captcha_code", "recaptcha_challenge_field", "recaptcha_response_field", "g-recaptcha-response");
$message .= $eol;
$message .= "IP Address : ";
$message .= $_SERVER['REMOTE_ADDR'];
$message .= $eol;
$logdata = '';
foreach ($_POST as $key => $value)
{
if (!in_array(strtolower($key), $internalfields))
{
if (!is_array($value))
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . $eol;
}
else
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . $eol;
}
}
}
$body = 'This is a multi-part message in MIME format.'.$eol.$eol;
$body .= '--'.$boundary.$eol;
$body .= 'Content-Type: text/plain; charset=UTF-8'.$eol;
$body .= 'Content-Transfer-Encoding: 8bit'.$eol;
$body .= $eol.stripslashes($message).$eol;
if (!empty($_FILES))
{
foreach ($_FILES as $key => $value)
{
if ($_FILES[$key]['error'] == 0)
{
$body .= '--'.$boundary.$eol;
$body .= 'Content-Type: '.$_FILES[$key]['type'].'; name='.$_FILES[$key]['name'].$eol;
$body .= 'Content-Transfer-Encoding: base64'.$eol;
$body .= 'Content-Disposition: attachment; filename='.$_FILES[$key]['name'].$eol;
$body .= $eol.chunk_split(base64_encode(file_get_contents($_FILES[$key]['tmp_name']))).$eol;
}
}
}
$body .= '--'.$boundary.'--'.$eol;
if ($mailto != '')
{
mail($mailto, $subject, $body, $header);
}
header('Location: '.$success_url); // tady je řádek 82, kde hlásí chybu
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Mujweb - Kontakt</title>
<meta name="author" content="Dyžon Soft">
<link href="necohezkeho.css" rel="stylesheet" type="text/css">
<link href="Kontakt.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="Header" style="position:absolute;text-align:center;left:0%;top:0px;width:100.614%;height:188px;z-index:19;">
<div id="Header_Container" style="width:1147px;position:relative;margin-left:auto;margin-right:auto;text-align:left;">
<div id="wb_imgHeader" style="position:absolute;left:99px;top:15px;width:916px;height:126px;z-index:0;">
<img src="images/header_1.png" id="imgHeader" alt=""></div>
<div id="wb_CssMenu" style="position:absolute;left:205px;top:158px;width:736px;height:26px;z-index:1;">
<ul>
<li class="firstmain"><a href="./index.html" target="_self" title="Úvod">Úvod</a>
</li>
<li><a href="./Galerie.html" target="_self" title="Galerie">Galerie</a>
</li>
<li><a href="http://www.mujweb.cz" target="_self" title="ukaz">ukaz</a>
</li>
<li><a class="active" href="./Kontakt.php" target="_self" title="Kontakt">Kontakt</a>
</li>
</ul>
</div>
</div>
</div>
<div id="Footer" style="position:absolute;text-align:center;left:0%;top:919px;width:100.614%;height:30px;z-index:20;">
<div id="Footer_Container" style="width:1147px;position:relative;margin-left:auto;margin-right:auto;text-align:left;">
<div id="wb_Shape1" style="position:absolute;left:0px;top:0px;width:58px;height:30px;z-index:14;">
<img src="images/img0002.png" id="Shape1" alt="" style="width:58px;height:30px;"></div>
<div id="wb_tCreated" style="position:absolute;left:1048px;top:11px;width:64px;height:14px;z-index:15;">
<span style="color:#696969;font-family:Arial;font-size:11px;">created:</span></div>
<div id="wb_imgDsLogo" style="position:absolute;left:1095px;top:8px;width:40px;height:16px;z-index:16;">
<img src="images/logo.png" id="imgDsLogo" alt=""></div>
<div id="wb_tCopyright" style="position:absolute;left:80px;top:10px;width:90px;height:14px;z-index:17;">
<span style="color:#696969;font-family:Arial;font-size:11px;">Copyright © 2015</span></div>
<!-- pocitadlo -->
<div id="htmlPocitadlo" style="position:absolute;left:973px;top:10px;width:42px;height:14px;z-index:18">
<script type="text/javascript" src="http://www.mujweb.eu/pocitadlonavstev/gcount.php?page=test"><!--
//--></script></div>
</div>
</div>
<div id="UnderHeader" style="position:absolute;text-align:center;left:0%;top:189px;width:100.614%;height:6px;z-index:21;">
<div id="UnderHeader_Container" style="width:1147px;position:relative;margin-left:auto;margin-right:auto;text-align:left;">
</div>
</div>
<div id="container">
<div id="wb_sPodKontaktem" style="position:absolute;left:33px;top:249px;width:244px;height:197px;z-index:22;">
<img src="images/img0003.png" id="sPodKontaktem" alt="" style="width:244px;height:197px;"></div>
<div id="wb_sPodMapou" style="position:absolute;left:307px;top:245px;width:832px;height:593px;z-index:23;">
<img src="images/img0001.png" id="sPodMapou" alt="" style="width:832px;height:593px;"></div>
<div id="wb_jsMapa" style="position:absolute;left:312px;top:249px;width:816px;height:578px;z-index:24;">
<div id="GoogleMaps" style="width:100%;height:100%;"></div>
<script type='text/javascript' src='http://maps.google.com/maps/api/js?key=YOUR_KEY'></script>
<script>
var map;
var marker;
var geocoder;
function GoogleMapInit(id, latitude, longitude, address)
{
var latlng = new google.maps.LatLng(latitude, longitude);
var latlngMarker = new google.maps.LatLng(latitude, longitude);
var mapOptions =
{
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
scrollwheel: true,
streetViewControl: true,
zoom: 13,
zoomControl: true,
zoomControlOptions: { style: google.maps.ZoomControlStyle.SMALL }
}
element = document.getElementById(id);
map = new google.maps.Map(element, mapOptions);
marker = new google.maps.Marker({ draggable:true, map: map, position: latlngMarker});
geocoder = new google.maps.Geocoder();
geocoder.geocode({'address': address}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker(
{
map: map,
position: results[0].geometry.location
});
}
else
{
// alert("Geocode was not successful: " + status);
}
});
}
GoogleMapInit('GoogleMaps', 20.7127837, -71.04683000002, '42.1977392, 18.6955164');
</script>
</div>
<div id="wb_blKontakt" style="position:absolute;left:43px;top:296px;width:212px;height:148px;z-index:25;">
<div>
<div class="bullet" style="height:30px;"><img src="images/postbullets.png" style="width:7px;height:11px;" alt=""></div>
<div class="item item0"><span style="color:#696969;font-family:'Arial Black';font-size:19px;line-height:26px;"><strong>jmeno prijmeni</strong></span></div>
</div>
<div style="clear:both">
<div class="bullet" style="height:26px;"><img src="images/postbullets.png" style="width:7px;height:11px;" alt=""></div>
<div class="item item1"><span style="color:#696969;font-family:'Arial Black';font-size:16px;line-height:23px;"><strong>ulice cislo</strong></span></div>
</div>
<div style="clear:both">
<div class="bullet" style="height:26px;"><img src="images/postbullets.png" style="width:7px;height:11px;" alt=""></div>
<div class="item item2"><span style="color:#696969;font-family:'Arial Black';font-size:16px;line-height:23px;"><strong>Mesto PSC</strong></span></div>
</div>
<div style="clear:both">
<div class="bullet" style="height:32px;"><img src="images/postbullets.png" style="width:7px;height:11px;" alt=""></div>
<div class="item item3"><span style="color:#FF8C00;font-family:'Arial Black';font-size:21px;line-height:30px;"><strong>123 456 789</strong></span></div>
</div>
<div style="clear:both">
<div class="bullet" style="height:18px;"><img src="images/postbullets.png" style="width:7px;height:11px;" alt=""></div>
<div class="item item4"><span style="color:#000000;font-family:Arial;font-size:13px;line-height:16px;"><strong><a href="mailto: dyzon@gmail.com">dyzon@mujweb.cz</a></strong></span></div>
</div>
</div>
<div id="wb_tKontakt" style="position:absolute;left:48px;top:259px;width:139px;height:19px;z-index:26;">
<span style="color:#8B4513;font-family:Arial;font-size:16px;"><strong>kontakt:</strong></span></div>
<hr id="lineKontakt" style="position:absolute;left:45px;top:279px;width:211px;height:2px;z-index:27;">
<div id="wb_fZprava" style="position:absolute;left:33px;top:469px;width:238px;height:354px;z-index:28;">
<form name="fZprava" method="post" action="<?php echo basename(__FILE__); ?>" enctype="multipart/form-data" accept-charset="UTF-8" id="fZprava">
<input type="hidden" name="formid" value="fzprava">
<div id="wb_tNapisteNam" style="position:absolute;left:13px;top:8px;width:139px;height:19px;z-index:2;">
<span style="color:#8B4513;font-family:Arial;font-size:16px;"><strong>napište nám:</strong></span></div>
<hr id="lineZprava" style="position:absolute;left:9px;top:29px;width:211px;height:2px;z-index:3;">
<div id="wb_tJmeno" style="position:absolute;left:24px;top:46px;width:72px;height:14px;z-index:4;">
<span style="color:#696969;font-family:Arial;font-size:11px;">jméno:</span></div>
<input type="text" id="eJmeno" style="position:absolute;left:16px;top:60px;width:198px;height:18px;line-height:18px;z-index:5;" name="kdo: " value="" spellcheck="false">
<div id="wb_tEmail" style="position:absolute;left:24px;top:90px;width:72px;height:14px;z-index:6;">
<span style="color:#696969;font-family:Arial;font-size:11px;">tvůj email:</span></div>
<input type="text" id="eEmail" style="position:absolute;left:16px;top:104px;width:198px;height:18px;line-height:18px;z-index:7;" name="od koho:" value="" spellcheck="false">
<div id="wb_tPredmet" style="position:absolute;left:24px;top:133px;width:72px;height:14px;z-index:8;">
<span style="color:#696969;font-family:Arial;font-size:11px;">předmět:</span></div>
<input type="text" id="ePredmet" style="position:absolute;left:16px;top:147px;width:198px;height:18px;line-height:18px;z-index:9;" name="předmět:" value="" spellcheck="false">
<div id="wb_tZprava" style="position:absolute;left:24px;top:176px;width:88px;height:14px;z-index:10;">
<span style="color:#696969;font-family:Arial;font-size:11px;">zpráva:</span></div>
<textarea name="zpráva:" id="etZprava" style="position:absolute;left:16px;top:190px;width:198px;height:119px;z-index:11;" rows="7" cols="36" spellcheck="false"></textarea>
<input type="submit" id="btOdeslat" name="" value="Odeslat" style="position:absolute;left:24px;top:320px;width:80px;height:25px;z-index:12;">
<input type="reset" id="btVymazat" name="" value="Vymazat" style="position:absolute;left:136px;top:320px;width:80px;height:25px;z-index:13;">
</form>
</div>
<div id="wb_imgShLevy" style="position:absolute;left:0px;top:903px;width:53px;height:46px;z-index:29;">
<img src="images/hrad_rychlejsi_naForm_trans.gif" id="imgShLevy" alt=""></div>
</div>
</body>
</html>
na netu jsem našel rady typu:
- smazat prazdny znaky před a po (<?php ; ?>) ,
- na začátek a konec připsat ob_start(); a ob_end_flush();
nic nepomohlo.
smazal jsem i řádek s echo, ale pořád to samé.
můžete mi prosím někdo poradit ??