Forum Moderators: coopster

Message Too Old, No Replies

Email notification issues

         

femiot

8:18 pm on Apr 13, 2012 (gmt 0)

10+ Year Member



Am actually trying to send an email notification pulling data from mysql(3 tables) but it seems not to yield... Can someone tell me what am doing wrong. I really need to send an email notification that includes courses, names and emails respectively. The notification is not sending at all. What are my mistakes please?

// Email Notification
if ($_POST['courses'] != '') {
$cid = $_POST['courses'];
$res = "SELECT * FROM course, course_student, student WHERE course.cid = course_student.cid AND course_student.sno ='$lastid' AND course.cname = '$cid'";
$rest = mysql_query($res) or die ();
$num1 = mysql_num_rows($rest);
$c = 0;
while($c < $num1) {
$courses = mysql_result($result, $c, 'cname');
$stud = mysql_result($result, $c, 'fname');
$studsur = mysql_result($result, $c, 'sname');
$c++;

$courses .= "$courses".";";
$stud .= "$stud".";";
$studsur .= "$studsur".";";

$student_info = "SELECT fname, sname, email FROM student WHERE contact_flag='Y'";
$result = mysql_query($student_info) or die ("Could not retrieve student info for mail: " . mysql_error());
$num = mysql_num_rows($result);
$i = 0;
while($i < $num){

$fname = mysql_result($result, $i, 'fname');
$sname = mysql_result($result, $i, 'sname');
$email = mysql_result($result, $i, 'email');
$i++;
$to2 .= "$fname".";";
$to3 .= "$sname".";";
$from = 'From: Info <noreply@oluwafemi.example.com>' . "\r\n";
$to .= "$email".";";
$subject = "Successfully Registered";
$body = "
---------------------------------------------
DO NOT REPLY TO THIS MESSAGE
---------------------------------------------

$fname $sname
This is a new student who have registered with our college.
Thank you!
Spartan College
List of classmates respectively:
courses: $courses
FirstNames: $stud
Surnames: $studsur

The list of students who chose to share their contacts are below respectively:
FirstNames:($to2)
Surnames:($to3)
Emails:($to)
";
}
}
}

[edited by: eelixduppy at 12:52 am (utc) on Apr 17, 2012]
[edit reason] example.com [/edit]

eelixduppy

12:54 am on Apr 17, 2012 (gmt 0)



I am not seeing you actually call any function that sends the email here...

rocknbil

5:10 pm on Apr 17, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$num1 = mysql_num_rows($rest);
$c = 0;
while($c < $num1) {
$courses = mysql_result($result, $c, 'cname');
$stud = mysql_result($result, $c, 'fname');
$studsur = mysql_result($result, $c, 'sname');
$c++;
}

Sorry, this veers O.T., but it always drives me nuts. After working out your email problem, and if you get it, you'll see how much more simple it's going to make your life.

You don't need to bloat your code by counting through results. Compare that with this.

$rest = mysql_query($res) or die ();
while ($row = mysql_fetch_array($rest)) {
$courses = $row['cname'];
$stud = $row['fname'];
$studsur = $row['sname'];
}

Boom. No counter, no complex code to debug, part of which is why you haven't found your missing mail() function sooner.

The real savings comes when you can do this entire bit of code in a single select statement without the second one. Let me know if you're interested in that. Everything on this page can be condensed to +- 25 lines of code.

femiot

1:41 am on Apr 18, 2012 (gmt 0)

10+ Year Member



Thanks guys... Am actually new to php... Don't smite me for my code arent appealing. Anyways, I found a way around what I wanted. Cheers!

eelixduppy

12:44 pm on Apr 18, 2012 (gmt 0)



>> Don't smite me for my code arent appealing.

I don't think he was "smiting" you -- just trying to help you understand an alternate, cleaner way to do the same thing for you to learn from. :)

Also, would you care to tell us how you figured out your problem?