Jump to content

Archived

This topic is now archived and is closed to further replies.

jeaker

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

Recommended Posts

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>[table][tr][td][/table]

Share this post


Link to post
Share on other sites
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..
[code]<?php
$email = $_POST[user_email];
$to = "$email";
$subject = "Grades";
$headers = "From: The PHP Master.";
mail($to, $subject, $line, $headers);
?>
[/code]
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

Share this post


Link to post
Share on other sites
you need to define $line before you use it first.


[code]

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

[/code]

Share this post


Link to post
Share on other sites
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>


Share this post


Link to post
Share on other sites

×

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.