Jump to content

Please help with syntax


lingo5

Recommended Posts

<?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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<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.

Link to comment
Share on other sites

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. :confused:

 

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.

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

$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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.