Help Setting up SendMail on Fedora 17

So me the code you have and I’ll help you out :slight_smile:

this part here…

//This is the “Mail From:” field
$mail->SetFrom(‘admin@medbuddy.com’, ‘Exam Coordinator’);
//This is the “Mail To:” field
$mail->AddAddress(“$studentEmailAddress”, ’ ');
$mail->Subject = ‘New Scores Uploaded’; //<-----------------------THIS ONE

could we replace this with the name of the subject the teacher selected in the dropdown menu, as in $_POST[“subject”]???i tried doing that but it gave me some syntax error…

$mail->Subject = $_POST['subject'].' Uploaded';

Or if you refactor it

send_mail($studentEmailAddress, $_POST['subject'].' Uploaded!', $message);

thanks, that too worked… :slight_smile: i’m almost getting there now, just a few more hurdles…this one is a bit about design, with my headers templates…is there a way i could make the one on the login.php page different from that on the teachers form page and students page??

for eg. this is what i have at the moment for two pages, login.php (my homepage) and teachers.php

and btw, the texts on the website the #1 blah blah are temporary… lol

I’m going to need to see the code in each file (login.php and teacher.php), plus any files they reference/render. Otherwise, I’m just guessing :slight_smile:

well these are my files… login.php

<?php

    // configuration
    require("../includes/config.php"); 

    // if form was submitted
    if ($_SERVER["REQUEST_METHOD"] == "POST")
    {
        // validate submission
        if (empty($_POST["username"]))
        {
            apologize("You must provide your username.");
        }
        else if (empty($_POST["password"]))
        {
            apologize("You must provide your password.");
        }

        // query database for user
        $rows = query("SELECT * FROM users WHERE username = ?", $_POST["username"]);

        // if we found user, check password
        if (count($rows) == 1)
        {
            // first (and only) row
            $row = $rows[0];

            // compare hash of user's input against hash that's in database
            if (crypt($_POST["password"], $row["hash"]) == $row["hash"])
            {
                // remember that user's now logged in by storing user's ID in session
                $_SESSION["id"] = $row["id"];

                // redirect to TEACHER portal
                redirect("teacher.php");
            }
        }

        // else apologize
        apologize("Invalid username and/or password.");
    }
    else
    {
        // else render form
        render("login_form.php", ["title" => "Log In"]);
    }

?>

2.TEACHER.PHP (HAVENT extracted yet)

<?php
  
    // display errors, warnings, and notices
    ini_set("display_errors", true);
    error_reporting(E_ALL);

    // requirements
    require("../includes/constants.php"); 
    require("../includes/functions.php");
    require_once("PHPMailer/class.phpmailer.php");
    // enable sessions
     session_start();
     
         // require authentication for most pages
    if (!preg_match("{(?:login|logout|register)\\.php$}", $_SERVER["PHP_SELF"]))
    {
        if (empty($_SESSION["id"]))
        {
            redirect("login.php");
        }
    }
     
     
     $validity = query("SELECT * FROM teachers");
     if ($_SESSION["id"]== $validity['0']["teacherid"])
    
    {
       $rows = query("SELECT * FROM users");
        // render form
       render("teacher_form.php", ["title" => "Teacher", "rows" => $rows]);
         
//After teacher has entered marks...........
         $message =<<<EMAIL_MESSAGE
Dear Student, for your information, scores for your most recent examination have been uploaded. Please visit Med Buddy to view your score. Thank you.
EMAIL_MESSAGE;
         if ($_SERVER["REQUEST_METHOD"] == "POST")
      {
         if (empty($_POST['subject']))
         apologize("Please select a subject");
         
      // run update query setting the mark for the subject to $value 
         foreach ($_POST['mark'] as $studentid => $value)
         {
           $subjectExistsForStudent = query("SELECT scores FROM marks WHERE studentid = ? AND subject = ?", $studentid, $_POST['subject']);
           if (sizeof($subjectExistsForStudent) === 0) 
           {
             $result = query("INSERT INTO marks (studentid, subject, scores) VALUES (?, ?, ?)", $studentid, $_POST['subject'], $value);
             
             if( $result===false)
             {
               apologize("Could not update student scores");
             }
             else
             {   
                
                 $studentEmailAddress = query("SELECT email FROM users WHERE id = ?", $studentid);
                 $studentEmailAddress = $studentEmailAddress['0']["email"];
                 
                
$mail = new PHPMailer(true);

$mail->IsSMTP();

try {
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "************"; // GMAIL username
$mail->Password = "************"; // GMAIL password

//This is the "Mail From:" field
$mail->SetFrom('admin@medbuddy.com', 'Exam Coordinator');
//This is the "Mail To:" field
$mail->AddAddress("$studentEmailAddress", ' ');
$mail->Subject = $_POST['subject'].' Scores Now Available'; 
$mail->Body = "Dear Student, for your information, scores for your most recent examination have been uploaded. 
\
Please visit Med Buddy at http://localhost/login.php to log in and view your score. Thank you.\

Sincerely,\

Exam Coordinator.";

$mail->Send();

} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
                     
             }
           }
           else
           {
             $result = query("UPDATE marks SET scores = ? WHERE studentid = ? AND subject = ?", $value, $studentid, $_POST['subject']);
             if( $result===false)
             {
               apologize("Could not update student scores");
             }
              else
             {   
                 
                 $studentEmailAddress = query("SELECT email FROM users WHERE id = ?", $studentid);
                 $studentEmailAddress = $studentEmailAddress['0']["email"];
                 
                 $mail = new PHPMailer(true);

$mail->IsSMTP(); ////////////////////////SHOULD I LEAVE IT LIKE THIS??

try {
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "**********"; // GMAIL username
$mail->Password = "**********"; // GMAIL password

//This is the "Mail From:" field
$mail->SetFrom('admin@medbuddy.com', 'Exam Coordinator');
//This is the "Mail To:" field
$mail->AddAddress("$studentEmailAddress", ' ');
$mail->Subject = $_POST['subject'].' Scores Updated'; 
$mail->Body = "Dear Student, for your information, scores for your most recent examination have been uploaded. 
\
Please visit Med Buddy at http://localhost/login.php to log in and view your score. Thank you.\

Sincerely,\

Exam Coordinator.";

$mail->Send();

} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
             }  
           }
         }
         
         
         
         
         
         
         
         
      }   
     }
     
     else
     { 
       redirect("student.php");
     }
  

?>

3.and header.php

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Med &middot; Buddy</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Le styles -->
    <<link href="css/bootstrap.css" rel="stylesheet"/>
    <link rel="stylesheet" href="css/font-awesome.css">
    <style type="text/css">
      body {
        padding-top: 20px;
        padding-bottom: 40px;
      }
      body { 
      background: url(img/capsule3.png) repeat 0 0;
      }
       
      /* Custom container */
      .container-narrow {
        margin: 0 auto;
        max-width: 700px;
      }
      .container-narrow > hr {
        margin: 30px 0;
      }

      /* Main marketing message and sign up button */
      .jumbotron {
        margin: 60px 0;
        text-align: center;
      }
      .jumbotron h1 {
        font-size: 72px;
        line-height: 1;
      }
      .jumbotron .btn i {
        margin-right: 8px;
      }

      /* Supporting marketing content */
      .marketing {
        margin: 60px 0;
      }
      .marketing p + h4 {
        margin-top: 28px;
      }
    </style>
    <link href="css/bootstrap-responsive.css" rel="stylesheet"/>

 
  </head>

  <body>
    <div class="container-narrow">

      <div class="masthead">
        <ul class="nav nav-pills pull-right">
          <li class="active"><a href="#">Home</a></li>
          <li><a href="login.php">Login</a></li>
          
        </ul>
        <h3 class="muted">MED BUDDY</h3>
      </div>

      <hr>

      <div class="jumbotron">
        <h1>The #1 stop for any medical student.</h1>
        <p class="lead">If you are a medical student, you couldn't have been luckier. Welcome to Med Buddy, the paradise of an aspiring doctor.</p>
        <a class="btn btn-large btn-success" href="register.php"><i class="icon-truck"></i> Sign up today</a>
        <a class="btn btn-large btn-success" href="login.php"><i class="icon-truck"></i> Already registered? Log in</a>
      </div>

      <hr>


      <hr>

   

Buzz! i guess it’s night at your end now? :smiley: :smiley:

Right on. I had a busy afternoon/evening yesterday, lots of meetings and then had all sorts of plans in the evening.

Looking at it, this should be fairly simple.

In your header.php find this line

<li><a href="login.php">Login</a></li>

Replace it with:

<?php if (isset($_SESSION['id']) && !empty($_SESSION['id'])) : ?>
<li><a href="logout.php">Logout</a></li>
<?php else: ?>
<li><a href="login.php">Login</a></li>
<?php endif; ?>

In short, we are looking to see if the user is logged in by checking the $_SESSION[‘id’] variable. Making sure it exists and it isn’t empty. If it exists and isn’t empty, we show a logout link, otherwise, we show a login link.

Then find this section of code in your header.php

      <div class="jumbotron">
        <h1>The #1 stop for any medical student.</h1>
        <p class="lead">If you are a medical student, you couldn't have been luckier. Welcome to Med Buddy, the paradise of an aspiring doctor.</p>
        <a class="btn btn-large btn-success" href="register.php"><i class="icon-truck"></i> Sign up today</a>
        <a class="btn btn-large btn-success" href="login.php"><i class="icon-truck"></i> Already registered? Log in</a>
      </div>

And replace it with

      <div class="jumbotron">
        <h1>The #1 stop for any medical student.</h1>
<?php if (!isset($_SESSION['id']) || empty($_SESSION['id'])) : ?>
        <p class="lead">If you are a medical student, you couldn't have been luckier. Welcome to Med Buddy, the paradise of an aspiring doctor.</p>
        <a class="btn btn-large btn-success" href="register.php"><i class="icon-truck"></i> Sign up today</a>
        <a class="btn btn-large btn-success" href="login.php"><i class="icon-truck"></i> Already registered? Log in</a>
<?php endif; ?>
      </div>

Then further down, we are checking the $_SESSION[‘id’] existence again, so we can hide the verbiage and the signup/login buttons.

thank you very much… i couldnt have done this without your help… do you have any advice regarding the look of the website? for instance i feel the colour of the LOGIN written above the login fields and other similar texts such as ENTER SUBJECTS etc. is just not right, it looks too pale… any opinion??

I’m glad it is working. :slight_smile:

To be honest, I didn’t spend a lot of time looking at the colors or the design (as we have a Review forum that is for that nature – but you must review three other sites before you can post your site for review).

I would encourage you to do that, as you could get useful remarks, and if you proceed with that route, I strongly recommend giving them in detail what you want reviewed, the color scheme, the text font choice, placement of text, etc. Anything you don’t want them to review, be sure to mention that too.

thank you for the suggestion, i really appreciate it :slight_smile: :)… could you please give me a link to the “Review section” ? and i was wondering since i’m quite new to the web stuff, how will i be able to review other people’s sites?? or is it just like giving some opinion about the beauty and features on their website and that’s all??

one last issue for now is, i’m trying to make a javascript for password validation, and this is what i currently have… i’m kind of stuck now and not sure on what to do next, could you kindly check this??

this is my regvalidation.js file

function formValidation()  
{  
 
var passid = document.registration.password;  
var uname = document.registration.username;  
  
var uemail = document.registration.email;  



if(passid_validation(passid,7,12))  
{  
if(allLetter(uname))  
{  
if(ValidateEmail(uemail))  
{   
}   
}  
}    
return false;  
}  

function passid_validation(passid,mx,my)  
{  
var passid_len = passid.value.length;  
if (passid_len == 0 ||passid_len >= my || passid_len < mx)  
{  
alert("Password should not be empty / length be between "+mx+" to "+my);  
passid.focus();  
return false;  
}  
return true;  
}  


function allLetter(uname)  
{   
var letters = /^[A-Za-z]+$/;  
if(uname.value.match(letters))  
{  
return true;  
}  
else  
{  
alert('Username must have alphabet characters only');  
uname.focus();  
return false;  
}  
}  


function ValidateEmail(uemail)  
{  
var mailformat = /^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+$/;  
if(uemail.value.match(mailformat))  
{  
return true;  
}  
else  
{  
alert("You have entered an invalid email address!");  
uemail.focus();  
return false;  
}  
} 

and this is my registration form…


<script src="js/regvalidation.js"></script>  
onload="document.registration.userid.focus();">  
<p class="lead">REGISTER</p> 
<p>Use tab keys to move from one input field to the next.</p>  
<form action="register.php" method="post" name='registration' onSubmit="return formValidation();">  
<fieldset>
        <div class="control-group">
            <input autofocus name="username" placeholder="Username" type="text"/>
        </div>
        <div class="control-group">
            <input name="password" placeholder="Password" type="password"/>
        </div>
        <div class="control-group">
            <input name="confirmation" placeholder="Confirm password" type="password"/>
        </div>
        <div class="control-group">
            <input name="email" placeholder="Enter Email" type="text"/>
        </div>
        
        <div class="control-group">
            <input name="security" placeholder="Security Keyword" type="text"/>
        </div>
        <div class="control-group">
            <button type="submit" class="btn">Register</button>
        </div>
    </fieldset>
</form>  
<div>
    or <a href="login.php">log in</a>
</div>
          

Website Design & Content Reviews & Critiques
Be sure to read this thread first, then post meaningful responses to ANY three threads in the forum. Be sure to provide meaningful remarks, “I like it” won’t count. Go into detail about why you like, what you would change, etc.

sure, i ll do that…thanks for the info…and did u find anything in the javascript??

I copied that to the JavaScript forum where you will hopefully get better help than I can provide. I’ve been out of the JavaScript landscape for nearly a year.

thanks man for everything…

if you’re not one of those guys, who think that the universe and everything in it came into existence out of nothing, i’ll just say “God bless you buddy”… :slight_smile: :slight_smile:

no replies, on javascript… guess not everyone is as good as you…