rcle Posted June 17, 2008 Share Posted June 17, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/110574-send-custimized-messages-to-email/ Share on other sites More sharing options...
KevinM1 Posted June 17, 2008 Share Posted June 17, 2008 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 />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/110574-send-custimized-messages-to-email/#findComment-567296 Share on other sites More sharing options...
rcle Posted June 17, 2008 Author Share Posted June 17, 2008 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 />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/110574-send-custimized-messages-to-email/#findComment-567323 Share on other sites More sharing options...
KevinM1 Posted June 17, 2008 Share Posted June 17, 2008 Mind posting your form? It's hard to see exactly what you want without it. Also, put your code in CODE tags. Press the # button to activate them. Quote Link to comment https://forums.phpfreaks.com/topic/110574-send-custimized-messages-to-email/#findComment-567327 Share on other sites More sharing options...
rcle Posted June 17, 2008 Author Share Posted June 17, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/110574-send-custimized-messages-to-email/#findComment-567487 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.