Jump to content

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


jeaker

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]
Link to comment
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
Link to comment
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]
Link to comment
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>


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.