king.oslo Posted June 11, 2009 Share Posted June 11, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/161821-what-happened-here/ Share on other sites More sharing options...
will35010 Posted June 11, 2009 Share Posted June 11, 2009 We'd have to see the script and form to make any real conclusions. Do you have form validation? Quote Link to comment https://forums.phpfreaks.com/topic/161821-what-happened-here/#findComment-853777 Share on other sites More sharing options...
king.oslo Posted June 11, 2009 Author Share Posted June 11, 2009 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 <cecilie@orchids.no>' . "\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 (cecilie@host.no) and one to confirmation to client-------------------------// mail('cecilie@host.no', $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>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/161821-what-happened-here/#findComment-853934 Share on other sites More sharing options...
rhodesa Posted June 11, 2009 Share Posted June 11, 2009 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/161821-what-happened-here/#findComment-853938 Share on other sites More sharing options...
king.oslo Posted June 11, 2009 Author Share Posted June 11, 2009 No, the user filled inn all information, I had confirmation of that in the body of the email. it seems the code making the $subject was skipped? But that cannot happen, right? Marius Quote Link to comment https://forums.phpfreaks.com/topic/161821-what-happened-here/#findComment-853943 Share on other sites More sharing options...
rhodesa Posted June 11, 2009 Share Posted June 11, 2009 nope...that shouldn't be able to happen with the code above.... Quote Link to comment https://forums.phpfreaks.com/topic/161821-what-happened-here/#findComment-853950 Share on other sites More sharing options...
king.oslo Posted June 11, 2009 Author Share Posted June 11, 2009 Given that the client submitted contents for all $_POST variables, what other reasons could it be that caused me to receive an empty subject? Thanks Marius Quote Link to comment https://forums.phpfreaks.com/topic/161821-what-happened-here/#findComment-854087 Share on other sites More sharing options...
rhodesa Posted June 12, 2009 Share Posted June 12, 2009 maybe an invalid character or a new line in the one of the post fields? Quote Link to comment https://forums.phpfreaks.com/topic/161821-what-happened-here/#findComment-854231 Share on other sites More sharing options...
king.oslo Posted June 12, 2009 Author Share Posted June 12, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/161821-what-happened-here/#findComment-854509 Share on other sites More sharing options...
Mark Baker Posted June 12, 2009 Share Posted June 12, 2009 How can I tell php to use the right charset in the subject? iconv_mime_encode() Quote Link to comment https://forums.phpfreaks.com/topic/161821-what-happened-here/#findComment-854546 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.