Jump to content

What happened here?


king.oslo

Recommended Posts

I have made a script which makes some calculations based on information entered in a form. This information is added to a variable. This variable is added to the subject line in a mail() function along with other $_POST vaiables.

 

Most of the time it works, but one user's email subject didn't contain any of this information. The subject of the emails was empty.

 

Is there any way a line of the script has been overlooked when executed, or did something else go wrong?

 

Thanks!

 

Marius

Link to comment
https://forums.phpfreaks.com/topic/161821-what-happened-here/
Share on other sites

I do not know what form validations are...

 

The script calculates the body mass index of the applicant. This is done by: "weight[kilograms] / (height[meters])*(height[meters])". But first i clean up the in-data in case the applicant was to include letters or other non symbols in their string.

 

Finally I compose the email and the troublesome subject string.

 

Thanks:

 

 <?php
//---------- REPLACES ',' with '.' converts cemtimeters and meters to prepare for $bm (body mass index) calculation----------//
$cleanv = str_replace(',','.', (preg_replace('~[^0-9,.]~', '', $_POST['vekt'])));	
if ((strlen($cleanh)) == 3){
$h = ($cleanh) / 100;										
}		
elseif ((strlen($cleanh)) == 2){								
$h = ($cleanh) / 10;										
}
else {
$h = 999999999
}

$bm = str_replace('.',',', (round (($cleanv / ($h*$h)), 2)));

//--------$headers & $headers2 of confirmation email to client and reminder to website owner-----------//

$headers = 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: Orchids.no <[email protected]>' . "\r\n";

$headers2 = 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers2 .= 'From: <' . $_POST['epost'] . '>' . "\r\n";

//-----------------body of emails------------------//
$topptekstepost = '<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
@charset "utf-8";
</style>
</head>

<body>';

$klient1 = '<p style="text-transform:capitalize; font-weight: bold;">Hei ' . $_POST['fornavn'] . ',</p><br>Takk for din søknad til å posere for Orchids.no! Vi synes det er <strong>tøft</strong> at du ønsker å bidra så personlig!<br><br>
  
  Dette er informasjonen du fylte ut:';

$vaar1 = '<p style="text-transform:capitalize; font-weight: bold;">Hei  Eiere!</p><br>
Jeg er et php-script og står til deres tjeneste! Vi har fått ennå en søknad. Den heldige har disse personlige detaljene. Takk!';


$resultat = '<br><br>
  Fornavn: ' . $_POST['fornavn'] . '<br>
  Etternavn: ' . $_POST['etternavn'] . '<br>
  Gateadresse: ' . $_POST['adr'] . '<br>
  Postnummer: ' . $_POST['postnr'] . '<br>
  Poststed: ' . $_POST['poststed'] . '<br>
  Epost: ' . $_POST['epost'] . '<br>
  Telefon: ' . $_POST['telefon'] . '<br>
  Alder (år): ' . $_POST['alder'] . '<br>
  Høyde (cm): ' . $_POST['hoyde'] . '<br>
  Vekt (kg): ' . $_POST['vekt'] . '<br>
  Hvorfor du ønsker å støtte saken: ' . $_POST['sak'];
  
$klient2 = '<br><br>
  
  Vi synes det er spennende å jobbe med så mange fantastiske kvinner. Takk!<br><br>
  
  <p style="text-transform:capitalize; font-weight: bold;">Mvh,<br>
  Cecilie Siljeholt<br>
  Orchids: Forbedrer vaginas verdighet!</p>';

$bunntekstepost = '</body></html>';

//---------------composing email------------------------//
$vaar_tekst = $topptekstepost . $vaar1 . $resultat . $bunntekstepost;
$klient_tekst = $topptekstepost . $klient1 . $resultat . $klient2 . $bunntekstepost;


//-----------------subject of email to host------------------------//
$subject = 'Navn: ' . $_POST['fornavn'] . ' ' . $_POST['etternavn'] . ', Alder: ' . $_POST['alder'] . ', idx: ' . $bm;

//-------------------mail functions. one email to host ([email protected]) and one to confirmation to client-------------------------//
mail('[email protected]', $subject , $vaar_tekst, $headers2);
mail ($_POST['epost'], 'Kvittering på søknad hos Orchids.no', $klient_tekst, $headers);

//---------------------------------Confirmation shown on screen to viewer-----------------------------------------------------//

Print '<h2><br><br>Takk for din søknad til å posere for Orchids.no! Vi synes det er <strong>tøft</strong> at du ønsker å bidra så personlig!<br><br>Dette er fylte du ut:' . $resultat . '<br><br><br>En kvittering har også blitt sendt til deg på epost! <br><br>Takk!</h2>';
?>

Link to comment
https://forums.phpfreaks.com/topic/161821-what-happened-here/#findComment-853934
Share on other sites

The fields are probably empty from the page being accessed without any POST data being sent. In the script that processes the data, just add a check at the beginning to make sure there was a POST:

<?php
  if($_SERVER['REQUEST_METHOD'] != 'POST')
    die("No data submitted");
?>

Link to comment
https://forums.phpfreaks.com/topic/161821-what-happened-here/#findComment-853938
Share on other sites

I have found the problem now! The subject uses the wrong charset. It used iso-8859-1 rather than utf-8. My email software was unable to recieve the subject.

 

How can I tell php to use the right charset in the subject? I ask for this is the header:

$headers = 'Content-type: text/html; charset=utf-8'

, but it seems it has not happened?

 

Thanks!

 

Marius

Link to comment
https://forums.phpfreaks.com/topic/161821-what-happened-here/#findComment-854509
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.