Hello guys!
I'm trying to make a script for a school website, so the principal can send mails to all of his students, teachers or other admins, it should be very simple but the page just keep coming blank or sending me syntax errors. Right now it's showing the following error:

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in correos.php on line 1

It gets the variables from another page (which is working). It receives the options (who should get the email, $correos), the message ($mensaje) and the title ($asunto).

<?php
//Chooses the mails
//Just one group
if ($_POST['Alumnos'] empty($_POST['Maestros']) empty($_POST['Admins')])) {
    $sql = "SELECT email FROM alumnos ORDER BY nombre";
    $result = mysql_query($sql,$db);
    while ($row = mysql_fetch_row($result)) {
        $correos .= "$row[0],";
    }
} elseif ($_POST['Maestros'] && empty($_POST['Alumnos']) empty($_POST['Admins'])) {
    $sql = "SELECT email FROM maestros WHERE Admin='0' ORDER BY nombre";
    $result = mysql_query($sql,$db);
    while ($row = mysql_fetch_row($result)) {
        $correos .= "$row[0],";
    }
} elseif ($_POST['Admins'] && empty($_POST['Alumnos']) && empty($_POST['Maestros'])) {
    $sql = "SELECT email FROM maestros WHERE Admin='1' ORDER BY email";
    $result = mysql_query($sql,$db);
    while ($row = mysql_fetch_row($result)) {
        $correos .= "$row[0],";
    }
//Students and/or others
} elseif ($_POST['Alumnos'] && $_POST['Maestros'] && empty($_POST['Admins'])) {
    $sql = "(SELECT email FROM alumnos) UNION (SELECT email FROM maestros) order by email";
    $result = mysql_query($sql,$db);
    while ($row = mysql_fetch_row($result)) {
        $correos .= "$row[0],";
    }
} elseif ($_POST['Alumnos'] && $_POST['Admins'] && empty($_POST['Maestros'])) {
    $sql = "(SELECT email FROM alumnos) UNION (SELECT email FROM maestros WHERE Admin='1') order by email";
    $result = mysql_query($sql,$db);
    while ($row = mysql_fetch_row($result)) {
        $correos .= "$row[0],";
    }
//teachers and/or others
} elseif ($_POST['Maestros'] && $_POST['Alumnos'] && empty($_POST['Admins'])) {
    $sql = "(SELECT email FROM maestros WHERE Admin='0') UNION (SELECT email FROM alumnos) order by email";
    $result = mysql_query($sql,$db);
    while ($row = mysql_fetch_row($result)) {
        $correos .= "$row[0],";
    }
} elseif ($_POST['Maestros'] && $_POST['Admins'] && empty($_POST['Alumnos'])) {
    $sql = "SELECT email FROM maestros ORDER BY email";
    $result = mysql_query($sql,$db);
    while ($row = mysql_fetch_row($result)) {
        $correos .= "$row[0],";
    }
//Admins and/or others
} elseif ($_POST['Admins'] && $_POST['Alumnos'] && empty($_POST['Maestros'])) {
    $sql = "(SELECT email FROM maestros WHERE Admin='1') UNION (SELECT email FROM alumnos) order by email";
    $result = mysql_query($sql,$db);
    while ($row = mysql_fetch_row($result)) {
        $correos .= "$row[0],";
    }
} elseif ($_POST['Admins'] && $_POST['Maestros'] && empty($_POST['Alumnos'])) {
    $sql = "SELECT email FROM maestros ORDER BY email";
    $result = mysql_query($sql,$db);
    while ($row = mysql_fetch_row($result)) {
        $correos .= "$row[0],";
    }   
//Everyone 
} elseif ($_POST['Admins'] && $_POST['Maestros'] && $_POST['Alumnos']) {
    $sql = "(SELECT email FROM maestros) UNION (SELECT email FROM alumnos) order by email";
    $result = mysql_query($sql,$db);
    while ($row = mysql_fetch_row($result)) {
        $correos .= "$row[0],";
    }    
}


    

//every variable send trough: $HTTP_POST_VARS.
$asunto = $_POST['asunto'];
$mensaje = $_POST['mensaje'];
//$headers = "From: efren.camacho@yoamoamericanways.com\r\n";
//$headers .= "Reply-To: efren.camacho@yoamoamericanways.com\r\n";
//$headers .= "Return-Path: efren.camacho@yoamoamericanways.com\r\n";
//$headers .= "MIME-Version: 1.0\r\n";
//$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";//
   
//Error checking
if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $correos)) {
    echo "<h4>Direccion de correo invalida!</h4>";
    echo "<a href='javascript:history.back(1);'>Regresar</a>";
} elseif (empty($asunto) or $asunto == "") {
    echo "<h4>Sin asunto</h4>";
    echo "<a href='javascript:history.back(1);'>Regresar</a>";

//Sends mail
} elseif (mail($correos,$asunto,$mensaje,"From: efren.camacho@yoamoamericanways.com")) {
    echo "<p align='center' class='input-container'><b>Correos Enviado Exitosamente!.</b></p>";
} else {
    echo "<p align='center' class='input-container'><b>Hubo un error por favor revisa los campos</b></p><br><p align='center' class='input-container'><b<a href='javascript:history.back(1);'>Regresar</a></b></p>";
}
?>

Sorry my code is so big, I know it's not very efficient, but I'm a newbie here, so I really couldn't find another way to do it :icon_redface:

Another thing it's that the page that sends the variables didn't work until I took out the comments

Thanks in advance!

Member Avatar for Zagga

Isn't this an exact copy of a post you made 2 hours ago?
Have a look at the reply from Will on that post.


Zagga

yeah it is =|
it took so long to load the page that I even thought it didn't went through

So embarrasing.

An admin can please errase this one?

So sorry.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.