Jump to content

[SOLVED] mail function


rugzo

Recommended Posts

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

<?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 ) ;
}

?>

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.