rugzo Posted December 29, 2008 Share Posted December 29, 2008 Hi all, i am a newbie and have a question about the php mail function. Everytime i call the page it sends the email which i actually want that it will be send after submitting the page. The other problem is that it sends a blank email instead of the values i define. The code looks like --> </td> </tr> <tr> <td>Training Document</td> <td><?php $sql = mysql_query ("SELECT * FROM subjects ORDER BY Id DESC LIMIT 1") ; while ($liste = mysql_fetch_array($sql)) { echo $liste[10]; } mysql_free_result($sql); ?> </td> </tr> </table> <?php $message = $_REQUEST['Subject'] ; $message = $_REQUEST['Troubleshoot'] ; $message = $_REQUEST['Knox'] ; $message = $_REQUEST['Summary'] ; $message = $_REQUEST['CTI'] ; $message = $_REQUEST['GR'] ; $message = $_REQUEST['Info'] ; $message = $_REQUEST['Description'] ; $message = $_REQUEST['Script'] ; $message = $_REQUEST['TrainingDocuments'] ; $headers = 'From: safi@nsn.com' ; mail( "ismet.alkaya@d.com , ozgur.ilhan.ext@d.com , numan.yilmaz.ext@d.com , erkin.yahyaoglu.ext@d.com" , "Project SAFI", $messasge, $headers ) ; ?> how can i prevent that it sends email every time the page is loaded and why is it sending a blank email istead of the variables i've choosen. thanks for your help best regards, (edited to add tags) Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 29, 2008 Share Posted December 29, 2008 You're clobbering the values in the $message variable each time. You need to concatenate them: <?php $msg = array('Subject','Troubleshoot','Knox','Summary','CTI','GR','Info','Description','Script','TrainingDocuments'); $message = ''; foreach ($msg as $itm) $message .= $itm . ': ' . $_REQUEST[$itm] . "\n"; ?> BTW, you shouldn't be using the $_REQUEST array. Always use either $_GET or $_POST depending on where the values are coming from. Ken Quote Link to comment Share on other sites More sharing options...
chronister Posted December 29, 2008 Share Posted December 29, 2008 Well, first off check your spelling. You mis-spelled the $message variable in the mail function. Also, your $message vars need to be concatenated. <?php $message = $_REQUEST['Subject'] ; $message .= $_REQUEST['Troubleshoot'] ; $message .= $_REQUEST['Knox'] ; $message .= $_REQUEST['Summary'] ; $message .= $_REQUEST['CTI'] ; $message .= $_REQUEST['GR'] ; $message .= $_REQUEST['Info'] ; $message .= $_REQUEST['Description'] ; $message .= $_REQUEST['Script'] ; $message .= $_REQUEST['TrainingDocuments'] ; ?> You should always check your spelling first when errors occur. Nate Quote Link to comment Share on other sites More sharing options...
rugzo Posted December 29, 2008 Author Share Posted December 29, 2008 Ok thanks, now the mail contains all the information but it still sends an email by the first call of the page. There is always a blank email on the first call??? if i can solve this one everything is solved for my project. thanksss... Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 29, 2008 Share Posted December 29, 2008 How are you invoking the script? I don't see a form. Ken Quote Link to comment Share on other sites More sharing options...
rugzo Posted December 29, 2008 Author Share Posted December 29, 2008 <html> <body bgcolor="#C0C0C0"> <br> <br> <form action="safientry.php" method="post" name="em"> <table align="center" cellspacing="0" cellpadding="0" border="1" bordercolor="#000000"> <tr> <td>Subject</td> <td> <textarea rows="3" cols="100" name="Subject"> </textarea> </td> </tr> <tr> <td>Troubleshoot</td> <td> <textarea rows="30" cols="100" name="Troubleshoot"> </textarea> </td> </tr> <tr> <td>Knox</td> <td> <textarea rows="3" cols="100" name="Knox"> </textarea> </td> </tr> <tr> <td>Summary</td> <td> <textarea rows="3" cols="100" name="Summary"> </textarea> </td> </tr> <tr> <td>CTI</td> <td> <textarea rows="3" cols="100" name="CTI"> </textarea> </td> </tr> <tr> <td>Group</td> <td> <textarea rows="3" cols="100" name="GR"> </textarea> </td> </tr> <tr> <td>Additional Information</td> <td> <textarea rows="3" cols="100" name="Info"> </textarea> </td> </tr> <tr> <td>Description</td> <td> <textarea rows="10" cols="100" name="Description"> </textarea> </td> </tr> <tr> <td>Script</td> <td> <textarea rows="3" cols="100" name="Script"> </textarea> </td> </tr> <tr> <td>Training Documents</td> <td> <textarea rows="3" cols="100" name="TrainingDocuments"> </textarea> </td> </tr> <tr> <td width="30"><input type="button" name="Gonderen" value="submit" size="20" onclick="if(em.Subject.value.length==0) alert('fill in completely'); else em.submit();"> </td> </tr> </table> </form> <?php @mysql_connect ("localhost", "root", "123*qwe123") or die (mysql_error()) ; @mysql_select_db ("kb") or die (mysql_error()) ; $Subject = $_POST["Subject"] ; $Troubleshoot = $_POST["Troubleshoot"] ; $Knox = $_POST["Knox"] ; $Summary = $_POST["Summary"] ; $CTI = $_POST["CTI"] ; $GR = $_POST["GR"] ; $Info = $_POST["Info"] ; $Description = $_POST["Description"] ; $Script = $_POST["Script"] ; $TrainingDocuments = $_POST["TrainingDocuments"] ; if ($Subject <>"") { $sql = "INSERT INTO subjects (Subject, Troubleshoot, Knox, Summary, CTI, GR, Info, Description, Script, TrainingDocuments) values ('$Subject', '$Troubleshoot', '$Knox', '$Summary', '$CTI', '$GR', '$Info', '$Description', '$Script', '$TrainingDocuments') " ; $kayit = mysql_query($sql) ; echo mysql_error() ; } ?> <table border="1" cellpadding="0" cellspacing="0"> <tr> <td>Id</td> <td><?php $sql = mysql_query ("SELECT * FROM subjects ORDER BY Id DESC LIMIT 1") ; while ($liste = mysql_fetch_array($sql)) { echo $liste[0]; } mysql_free_result($sql); ?></td> </tr> <tr> <td>Subject</td> <td><?php $sql = mysql_query ("SELECT * FROM subjects ORDER BY Id DESC LIMIT 1") ; while ($liste = mysql_fetch_array($sql)) { echo $liste[1]; } mysql_free_result($sql); ?></td> </tr> <tr> <td>Troubleshoot</td> <td><?php $sql = mysql_query ("SELECT * FROM subjects ORDER BY Id DESC LIMIT 1") ; while ($liste = mysql_fetch_array($sql)) { echo $liste[2]; } mysql_free_result($sql); ?></td> </tr> <tr> <td>Knox</td> <td><?php $sql = mysql_query ("SELECT * FROM subjects ORDER BY Id DESC LIMIT 1") ; while ($liste = mysql_fetch_array($sql)) { echo $liste[3]; } mysql_free_result($sql); ?></td> </tr> <tr> <td>Summary</td> <td><?php $sql = mysql_query ("SELECT * FROM subjects ORDER BY Id DESC LIMIT 1") ; while ($liste = mysql_fetch_array($sql)) { echo $liste[4]; } mysql_free_result($sql); ?></td> </tr> <tr> <td>CTI</td> <td><?php $sql = mysql_query ("SELECT * FROM subjects ORDER BY Id DESC LIMIT 1") ; while ($liste = mysql_fetch_array($sql)) { echo $liste[5]; } mysql_free_result($sql); ?></td> </tr> <tr> <td>Group</td> <td><?php $sql = mysql_query ("SELECT * FROM subjects ORDER BY Id DESC LIMIT 1") ; while ($liste = mysql_fetch_array($sql)) { echo $liste[6]; } mysql_free_result($sql); ?></td> </tr> <tr> <td>Additional Information</td> <td><?php $sql = mysql_query ("SELECT * FROM subjects ORDER BY Id DESC LIMIT 1") ; while ($liste = mysql_fetch_array($sql)) { echo $liste[7]; } mysql_free_result($sql); ?></td> </tr> <tr> <td>Description</td> <td><?php $sql = mysql_query ("SELECT * FROM subjects ORDER BY Id DESC LIMIT 1") ; while ($liste = mysql_fetch_array($sql)) { echo $liste[8]; } mysql_free_result($sql); ?></td> </tr> <tr> <td>Script</td> <td><?php $sql = mysql_query ("SELECT * FROM subjects ORDER BY Id DESC LIMIT 1") ; while ($liste = mysql_fetch_array($sql)) { echo $liste[9]; } mysql_free_result($sql); ?></td> </tr> <tr> <td>Training Document</td> <td><?php $sql = mysql_query ("SELECT * FROM subjects ORDER BY Id DESC LIMIT 1") ; while ($liste = mysql_fetch_array($sql)) { echo $liste[10]; } mysql_free_result($sql); ?> </td> </tr> </table> <?php $message = $_REQUEST['Subject'] ; $message .= $_REQUEST['Troubleshoot'] ; $message .= $_REQUEST['Knox'] ; $message .= $_REQUEST['Summary'] ; $message .= $_REQUEST['CTI'] ; $message .= $_REQUEST['GR'] ; $message .= $_REQUEST['Info'] ; $message .= $_REQUEST['Description'] ; $message .= $_REQUEST['Script'] ; $message .= $_REQUEST['TrainingDocuments'] ; $headers .= 'From: safi@d.com' ; mail( "ozgext@d.com", "Project SAFI", $message, $headers ) ; ?> <br> <br> <br> <br> <br> <br> <br> <br> <i><font face="verdana" size="1" > copyright Özgürd</font></i> </body> </html> Quote Link to comment Share on other sites More sharing options...
chronister Posted December 29, 2008 Share Posted December 29, 2008 <?php if(isset($_POST['Gonderen'])) { $message = $_REQUEST['Subject'] ; $message .= $_REQUEST['Troubleshoot'] ; $message .= $_REQUEST['Knox'] ; $message .= $_REQUEST['Summary'] ; $message .= $_REQUEST['CTI'] ; $message .= $_REQUEST['GR'] ; $message .= $_REQUEST['Info'] ; $message .= $_REQUEST['Description'] ; $message .= $_REQUEST['Script'] ; $message .= $_REQUEST['TrainingDocuments'] ; $headers .= 'From: safi@d.com' ; mail( "ozgext@d.com", "Project SAFI", $message, $headers ) ; } ?> Quote Link to comment Share on other sites More sharing options...
rugzo Posted December 29, 2008 Author Share Posted December 29, 2008 Thanks very much... 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.