0

The following code functions in part. The problem area, I believe, is near the query portion. After tbody, if I include the concatenate period (.) the code works, except the query itself becomes part of the message.

If I remove it, I receive a parse error (Parse error: syntax error, unexpected '$sql' (T_VARIABLE)). I am stuck.

Here is the result with the concatenation included:

Client List Report requested by: Jim

ID Name Address City State Zip Telephone Contact Email

SELECT * FROM client ORDER BY name
1 Duke and Duke 5555 Rockefeller Plaza New York NY 10055 212-555-1212 Mortimer Duke Randolph.Duke@Duke.com

Any assistance is appreciated!

//***********************  Email client list   ***********************//
if(isset($_POST['action']) && $_POST['action'] === 'email client list')
{
    include '../includes/dbconnect-local.php';


     /********  Prepare to mail  *********/

    // Recipients
    $jim = 'jim@gmail.com';

    $to = $jim;
    $from = 'Administrator@company.com';

    // Subject
    $subject = 'Client List';

    // Message
    $message = '
        <html>
        <body>
        <h2>Client List</h2>
        <h3>Report requested by: ' . $_SESSION['name']  . '</h3>
        <table style="width:100%;">
        <thead>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Address</th>
                <th>City</th>
                <th>State</th>
                <th>Zip</th>
                <th>Telephone</th>
                <th>Contact</th>
                <th>Email</th>
            <tr>
        </thead>
        <tbody>
     ' .

    // Get all client data
    $sql = 'SELECT * FROM client ORDER BY name';
    $result = $db->query($sql);

    while($row = $result->fetch(PDO::FETCH_ASSOC))
    {                         
        $message .= '<tr>';
        $message .=         '<td>' . htmlspecialchars($row['id']) . '</td>';
        $message .=         '<td>' . htmlspecialchars($row['name']) . '</td>';
        $message .=         '<td>' . htmlspecialchars($row['address']) . '</td>';
        $message .=         '<td>' . htmlspecialchars($row['city']) . '</td>';
        $message .=         '<td>' . htmlspecialchars($row['state']) . '</td>';
        $message .=         '<td>' . htmlspecialchars($row['zip']) . '</td>';
        $message .=         '<td>' . htmlspecialchars($row['telephone']) . '</td>';
        $message .=         '<td>' . htmlspecialchars($row['contact_name']) . '</td>';
        $message .=         '<td>' . htmlspecialchars($row['contact_email']) . '</td>';
        $message .= '<tr>';
    }
    $message .= '
    </tbody>
    </table> 
    </body>
    </html>';

    // To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    // Additional headers
    $headers .= 'To: ' . "\r\n";
    $headers .= 'From: ' . $from . "\r\n";
    $headers .= 'Cc: ' . "\r\n";
    $headers .= 'Bcc: ' . "\r\n";

    // Mail it
    mail($to, $subject, $message, $headers);  

    // Redirect
    header('Location: .');
    exit();     
} 
JimB814
  • 510
  • 8
  • 24
  • Please provide link to this question where previously asked. I was unable to find an answer here or elsewhere online. Help was found @ http://stackoverflow.com/questions/8900094/retrieve-data-from-mysql-and-email-it, but this code fails at the point noted above. Thanks. – JimB814 Sep 24 '15 at 13:46
  • @johnconde I saw the link at the top which I did not see earlier, and followed it. Thanks! The solution was there and I am happy to learn where the error was (a semicolon). Thanks for taking the time to review my question. – JimB814 Sep 24 '15 at 13:57

0 Answers0