lingo5 Posted November 4, 2015 Share Posted November 4, 2015 <?php if(isset($_POST['submit'])) { $name = $_POST['name']; $email = $_POST['email']; $tel = $_POST['tel']; $province = $_POST['province']; $city = $_POST['city']; $query = $_POST['message']; $email_from = $name.'<'.$email.'>'; $to="info@email.com"; $subject="Alguien quiere un presupuesto"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= "From: ".$email_from."\r\n"; $message=" Nombre: $name <br> Tel.: $tel <br> Email: $email <br> Provincia: $province <br> Ciudad: $city <br> Descripcion: $query "; if(mail($to,$subject,$message,$headers)) header("Location:../presupuesto.php?msg=<?=CNT_TXT_WARNING_EMAILSENTOK?>"); else header("Location:../presupuesto.php?msg=<?=CNT_TXT_WARNING_EMAILSENTERROR?>"); } ?> Hi, I have created a mailing script and it works fine, but I can't get it to print the success/error messages. Many thanks Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 4, 2015 Share Posted November 4, 2015 What is CNT_TXT_WARNING_EMAILSENTOK and CNT_TXT_WARNING_EMAILSENTERROR are they constants or they literal strings for the msg query string value? Quote Link to comment Share on other sites More sharing options...
shan Posted November 4, 2015 Share Posted November 4, 2015 same question here?? @lingo5 Quote Link to comment Share on other sites More sharing options...
lingo5 Posted November 4, 2015 Author Share Posted November 4, 2015 Hi Ch0cu3r, they're strings of text to show the message in different languages. Quote Link to comment Share on other sites More sharing options...
lingo5 Posted November 4, 2015 Author Share Posted November 4, 2015 Hi Shan, please see my answer. Thanks Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 4, 2015 Share Posted November 4, 2015 Hi Ch0cu3r, they're strings of text to show the message in different languages. Then remove the PHP short tags <?= ?> Quote Link to comment Share on other sites More sharing options...
lingo5 Posted November 4, 2015 Author Share Posted November 4, 2015 CNT_TXT_WARNING_EMAILSENTOK thanks but that doesn't seem to work, all I get is this printed when the form has ben submitted Quote Link to comment Share on other sites More sharing options...
Barand Posted November 4, 2015 Share Posted November 4, 2015 You need to concatenate header("Location:../presupuesto.php?msg=" . CNT_TXT_WARNING_EMAILSENTO); Quote Link to comment Share on other sites More sharing options...
lingo5 Posted November 4, 2015 Author Share Posted November 4, 2015 sorry, still doing the same. ?¿?¿?? Quote Link to comment Share on other sites More sharing options...
lingo5 Posted November 4, 2015 Author Share Posted November 4, 2015 nope.... thanks but not displaying the message correctly. Quote Link to comment Share on other sites More sharing options...
shan Posted November 4, 2015 Share Posted November 4, 2015 try this: @lingo5 if(mail($to,$subject,$message,$headers)){ header("Location:../presupuesto.php?msg=CNT_TXT_WARNING_EMAILSENTOK"); }else{ header("Location:../presupuesto.php?msg=CNT_TXT_WARNING_EMAILSENTERROR"); } if it doesnt work then check the presupuesto.php location and put the appropriate file path. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted November 4, 2015 Share Posted November 4, 2015 nope.... thanks but not displaying the message correctly. it would help if you state what it is actually doing, and where it is doing it. if you are only getting part of the message or it is being stripped of any non-ascii characters on the page that the header() redirect goes to, it's probably because you need to use urlencode() on any data you pass through a url Quote Link to comment Share on other sites More sharing options...
lingo5 Posted November 4, 2015 Author Share Posted November 4, 2015 Hi @shan, thanks but all I get printed on presupuesto.php is this CNT_TXT_WARMING_EMAILSENTOK instead of the actual success message. The filepath is correct. Quote Link to comment Share on other sites More sharing options...
lingo5 Posted November 4, 2015 Author Share Posted November 4, 2015 <div class="row-fluid"> <div class="span8" id="divMain2"> <h3 style="color:#FF6633;"><?php echo $_GET[msg];?></h3> <hr> <!--Start Contact form --> <form name="enq" method="post" action="email/" onsubmit="return validation();"> <fieldset> <input type="text" name="name" id="name" value="Nombre" class="input-block-level" placeholder=<?=CNT_TXT_PRESUPUESTO_NOMBRE?> /> <input type="text" name="tel" id="tel" value="Tel" class="input-block-level" placeholder=<?=CNT_TXT_PRESUPUESTO_TELEFONO?> /> <input type="text" name="email" id="email" value="Email" class="input-block-level" placeholder=<?=CNT_TXT_PRESUPUESTO_EMAIL?> /> <input type="text" name="province" id="province" value="Provincia" class="input-block-level" placeholder=<?=CNT_TXT_PRESUPUESTO_PROVINCIA?> /> <input type="text" name="city" id="city" value="Ciudad" class="input-block-level" placeholder=<?=CNT_TXT_PRESUPUESTO_CIUDAD?> /> <textarea rows="11" name="message" id="message" class="input-block-level" placeholder=<?=CNT_TXT_PRESUPUESTO_DESCRIPCION?>></textarea> <div class="actions"> <input type="submit" value=<?=CNT_TXT_BOTONES_ENVIAR?> name="submit" id="submitButton" class="btn btn-info pull-right" title="" /> </div> </fieldset> </form> <!--End Contact form --> </div> please see my answer to shan. In addition to that here's the code for the presupuesto.php page that shows my form and right at the top the php code that shoud print the sent ok message. Quote Link to comment Share on other sites More sharing options...
Barand Posted November 4, 2015 Share Posted November 4, 2015 Do have CNT_TXT_WARNING_EMAILSENTOK defined anywhere, for example define("CNT_TXT_WARNING_EMAILSENTOK", "This is a message to say it is OK"); Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted November 4, 2015 Share Posted November 4, 2015 Hi @shan, thanks but all I get printed on presupuesto.php is this CNT_TXT_WARMING_EMAILSENTOK instead of the actual success message. The filepath is correct. that's because the syntax/code that shan posted is incorrect. the correct syntax is what Barand showed in post #8. please post your current code where the header() redirect statements are at. Quote Link to comment Share on other sites More sharing options...
shan Posted November 4, 2015 Share Posted November 4, 2015 (edited) @lingo5 are you trying to get that message and display an alert box or anything using $_GET global variable ??? Edited November 4, 2015 by shan Quote Link to comment Share on other sites More sharing options...
lingo5 Posted November 4, 2015 Author Share Posted November 4, 2015 Barand yes, I have it defined in a txt file. All other message in that file are working correctly. Quote Link to comment Share on other sites More sharing options...
lingo5 Posted November 4, 2015 Author Share Posted November 4, 2015 (edited) @shan yes, that's what I'm trying to do Edited November 4, 2015 by lingo5 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted November 4, 2015 Share Posted November 4, 2015 i recommend that the OP reread (some of) the replies, particularly post #8 (that change applies to both of the statements you have in your code), and the suggestion to please post your current code where the header() redirect statements are at. Quote Link to comment Share on other sites More sharing options...
lingo5 Posted November 4, 2015 Author Share Posted November 4, 2015 <?php if(isset($_POST['submit'])) { $name = $_POST['name']; $email = $_POST['email']; $tel = $_POST['tel']; $province = $_POST['province']; $city = $_POST['city']; $query = $_POST['message']; $email_from = $name.'<'.$email.'>'; $to="info@email.com"; $subject="Alguien quiere un presupuesto"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= "From: ".$email_from."\r\n"; $message=" Nombre: $name <br> Tel.: $tel <br> Email: $email <br> Provincia: $province <br> Ciudad: $city <br> Descripcion: $query "; if(mail($to,$subject,$message,$headers)) header("Location:../presupuesto.php?msg=" . CNT_TXT_WARNING_EMAILSENTOK); else header("Location:../presupuesto.php?msg=" . CNT_TXT_WARNING_EMAILSENTERROR); } ?> @mac_gyver here's the code with the changes suggested in post 8. Still no luck. Quote Link to comment Share on other sites More sharing options...
Barand Posted November 4, 2015 Share Posted November 4, 2015 You said that "CNT_TXT_WARNING_EMAILSENTOK" is defined in a text file. How do you get it from said text file to that script? Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted November 4, 2015 Share Posted November 4, 2015 With all due respect, lingo5: You should just throw your code away and start from scratch, this time with a proper mailer library and a basic understanding of security. What you've written there is malware (even if that certainly wasn't intended). You allow anybody to inject arbritrary content into the e-mail and send it to arbitrary people over your server. This is called an open mail relay, and it's one of the reasons why our inboxes keep getting flooded with spam. As soon your hoster realizes that your application spreads Viagra spam, you can be pretty sure that you're not welcome anymore. In the worst case, the hoster itself will end up on a spam blacklist, and that's when people really get pissed off. So, please, don't just upload code you found somewhere on the Internet. Learn the basics of security and use established libraries instead of copy-pasting crap code. Quote Link to comment Share on other sites More sharing options...
lingo5 Posted November 5, 2015 Author Share Posted November 5, 2015 Hi @Jacques1, I know my code is not professional... but that is because I'm just a amateur programmer myself. I do this for fun an I never upload it to any real life servers (I'm a psychologist !!!!). I know I have a lot to learn and that's why I come here !!! Sorry guys if I'm wasting your time. Quote Link to comment Share on other sites More sharing options...
lingo5 Posted November 5, 2015 Author Share Posted November 5, 2015 $idioma=strtolower($idioma); if ($idioma=="esp" || $idioma=="eng" || $idioma=="ger"){ $_SESSION['session_idioma'] = $idioma; } if (!$_SESSION['session_idioma']){ $_SESSION['session_idioma'] = "esp"; } // define (IDIOMA,$_SESSION['session_idioma']); $IDIOMA = $_SESSION['session_idioma']; include "cntTxt_$IDIOMA.php3"; define ('CNT_TXT_WARNING_EMAILSENTOK',"email sent correctly"); define ('CNT_TXT_WARNING_EMAILSENTERROR',"there was an error sending your email"); @Barand, I define these constants in a txt file called cntTXT_eng for English language like so: Then I have created a php file called constants like this: I then include the constans php file at the top of the page. It works site wide except for the contact form. Quote Link to comment 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.