Jump to content

Recommended Posts

Hello everybody,

 

Is there a way to custimize a message for an email for more than one value?

---------------------------------------------------------------------------------

<?php

  $x = count($_POST['field2']);

 

  for($i=0;$i<$x;$i++)

  {

    $message .= 'You ordered product ' . $_POST['field2'][$i];

  }

?>

----------------------------------------------------------------------------------

for example , i want to add more values to my main $message .= 'You ordered product ' . $_POST['field2'][$i]; ----> field3,4,5,6,

 

I also want to put <br/> in my messages and i don't want to repeat the message in my email.

 

In this code, the message keeps repeating for each value.

 

THANK YOU GUYS FOR THE HELP!

Link to comment
https://forums.phpfreaks.com/topic/110574-send-custimized-messages-to-email/
Share on other sites

Hello everybody,

 

Is there a way to custimize a message for an email for more than one value?

---------------------------------------------------------------------------------

<?php

  $x = count($_POST['field2']);

 

  for($i=0;$i<$x;$i++)

  {

    $message .= 'You ordered product ' . $_POST['field2'][$i];

  }

?>

----------------------------------------------------------------------------------

for example , i want to add more values to my main $message .= 'You ordered product ' . $_POST['field2'][$i]; ----> field3,4,5,6,

 

I also want to put <br/> in my messages and i don't want to repeat the message in my email.

 

In this code, the message keeps repeating for each value.

 

THANK YOU GUYS FOR THE HELP!

 

Looks like you're having some array trouble.

 

Remember: the superglobal values (i.e. $_POST, $_GET, etc) are the arrays.  Every time you use square-bracket notation with them ($_POST['field2']), you're specifying an individual element of that array, located at the value specified within those brackets.  In your case, your value is repeating because you're telling it to hit field2 repeatedly.

 

Now, here's what you should do:

<?php
   $length = count($_POST) - 1; //don't want to include the submit button
   $message .= "You ordered product(s):<br /><br />";

   for($i = 0; i < $length; i++)
   {
      $message .= "{$_POST[$i]} <br />";
   }
?>

Thank you, but where do i put my checkbox names for example "field2"?

 

<?php

  $length = count($_POST) - 1; //don't want to include the submit button

  $message .= "You ordered product(s):<br /><br />";

 

  for($i = 0; i < $length; i++)

  {

      $message .= "{$_POST[$i]} <br />";

  }

?>

Thank you.

 

Hello, this is my html form.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>

<script src="prototype.js" type="text/javascript"></script>

<script type="text/javascript" src="validation.js"></script>

<link rel="stylesheet" type="text/css" href="style.css" />

</head>

<body>

<form id="test" action="multipleselections.php" method="post">

 

    <fieldset>

      <legend>Orderformulier</legend>

      <div class="form-row">

      <div class="field-label"><label for="field1">Naam</label>:</div>

      <div class="field-widget"><input name="field1" id="field1" class="required" title="Vul hier uw naam in" /></div>

      </div>

  <div class="form-row">

 

      <div class="field-label"><label for="field2">Overzicht producten:</label>:</div>

      <div class="field-label">

        <input type="checkbox" name="field2[]" id="field2-prcode001" value="product001" />product001<br />

        <input type="checkbox" name="field2[]" id="field2-prcode002" value="product002" />product002<br />

<input type="checkbox" name="field2[]" id="field2-prcode003" value="product003" />product003<br />

<input type="checkbox" name="field2[]" id="field2-prcode004" value="product004" class="validate-one-required" />product004<br />

 

      </div>

      </div>

      <div id="email-signup" class="form-row" style="display:true;">

  <div class="field-label"><label for="field3">Email adres</label>:</div>

      <div class="field-widget"><input name="field3" id="field3" class="required validate-email" title="Vul hier een geldig emailadres in" /></div>

      </div>

    </fieldset>

    <input type="submit" value="Verzend order" /> <input type="button" value="Reset" onclick="valid.reset(); return false" />

 

    </form>

    <script type="text/javascript">

function formCallback(result, form) {

      window.status = "valiation callback for form '" + form.id + "': result = " + result;

      }

     

      var valid = new Validation('test', {immediate : true, onFormValidate : formCallback});

    </script>

</body>

</html>

-------------------------------------------------------------------------------------------------------------------------------------

This is my php form.

 

<?php

 

$my_email = "raf.clerx@dedicatedweb.be";

$continue = "/";

$product = "";

if ($_SERVER['REQUEST_METHOD'] != "POST"){exit;}

 

 

print ("U heeft onderstaande producten besteld:<br />");

 

if(is_array($_POST['field2']))

{

foreach($_POST['field2'] as $product)

{

print ("$product<br />");

}

}

 

  $length = count($_POST['field2']) - 1 ;

 

  $message .= "You ordered product(s):<br /><br />";

 

  for($i = 0; i < $length; i++)

  {

      $message .= "{$_POST['field2'][$i]} <br />";

  }

$message = $message ;

$message = stripslashes($message);

 

$subject = "inschrijving ";

$headers = "From: " . $_POST['field3'] . "\n" . "Return-Path: " . $_POST['field3'] . "\n";

 

mail($my_email,$subject,$message,$headers,$_POST['field3']);

?>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head><title>test</title></head>

<body>

<div align="left"><span class="style1"><b>Bedankt voor uw order <?php print stripslashes($_POST['field3']); ?>!</b>

  <br/>

  Wij behandelen uw bestelling zo vlug mogelijk.</span>

  </div>

</body>

</html>

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.