Jump to content


Photo

Any experts on using the mail() funtion????


  • Please log in to reply
3 replies to this topic

#1 jeaker

jeaker
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 25 October 2006 - 10:30 PM

I am attempting to get get this script to now e-mail the user everything that was already printed out to the screen.
The output is a series of last names first names and the GPA. I would like that all to be email to the user. I think i am pretty close with this script but cannot figure out how to get the whole thing to be emailed.
Any help is greatly appreciated.
???



<?php
$to = "$_POST[user_email]";
$subject = "Grades";
$headers = "From: The PHP Master.";
mail($to, $subject, $headers, $line);
?>
<html>
<head>
<title>Mailing Data From a File</title>
</head>
<body>
<?php
$line = file("Grades.txt");
$i = 0;
$num = 0;
$cnt = 0;
while ($line[$i] != -2) {
      $first = $line[$i];
      $i++;
      $last = $line[$i];
      $i++;
  while ($line[$i] != -1) {
        $num = $num + $line[$i];
        $cnt++;
        $i++;
        }
$num = $cnt > 0 ? $num / $cnt : 0;
echo "$last, $first, $num<br />";
$i++;
$cnt = 0;
$num = 0;
}
?>
</body>
</html>[tr][td]


#2 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 26 October 2006 - 12:13 AM

ummm im guessing that the line variable is the message right? in the mail function you need it to be, to email address, subject, message, headers.. you have it mixed up a little.. if $line is the message the email function in your script should look like this..
<?php
$email = $_POST[user_email];
$to = "$email";
$subject = "Grades";
$headers = "From: The PHP Master.";
mail($to, $subject, $line, $headers);
?>
ahh if your trying to send all that html stuff in the email then im not sure how to do that.. hope this still helps you though cause i think you were sending the mail the wrong way.. im pretty sure it matters lol

#3 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 26 October 2006 - 12:15 AM

you need to define $line before you use it first.



<html>
<head>
<title>Mailing Data From a File</title>
</head>
<body>
<?php
$line = file("Grades.txt");
$i = 0;
$num = 0;
$cnt = 0;
while ($line[$i] != -2) {
      $first = $line[$i];
      $i++;
      $last = $line[$i];
      $i++;
   while ($line[$i] != -1) {
         $num = $num + $line[$i];
         $cnt++;
         $i++;
         }
$num = $cnt > 0 ? $num / $cnt : 0;
echo "$last, $first, $num
";
$i++;
$cnt = 0;
$num = 0;
}
?>
<?php
$email = $_POST[user_email];
$to = "$email";
$subject = "Grades";
$headers = "From: The PHP Master <youremail>";
mail($to, $subject, $line, $headers);
?>
</body>
</html>



#4 jeaker

jeaker
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 26 October 2006 - 01:53 AM

I have tried using this code below(taking the above advice)...everything prints out ok to the screen but the e-mail that i receive is always blank. I cannot for the life of me figure out why?? Any thoughts???
Thank you both for the help.

<?php
$email = $_POST[user_email];
$to = "$email";
$subject = "Grades";
$headers = "From: The PHP Master.";
mail($to, $subject, $line, $headers);
?>
<html>
<head>
<title>Mailing Data From a File</title>
</head>
<body>
<?php
$line = file("Grades.txt");
$i = 0;
$num = 0;
$cnt = 0;
while ($line[$i] != -2) {
      $first = $line[$i];
      $i++;
      $last = $line[$i];
      $i++;
  while ($line[$i] != -1) {
        $num = $num + $line[$i];
        $cnt++;
        $i++;
        }
$num = $cnt > 0 ? $num / $cnt : 0;
echo "$last, $first, $num<br />";
$i++;
$cnt = 0;
$num = 0;
}
?>
</body>
</html>







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users