Mysql
 sql >> Database >  >> RDS >> Mysql

recuperare i dati da mysql e inviarli tramite e-mail

a seconda della fonte dei tuoi dati mysql e di come sono archiviati, non puoi recuperarli e aggiungerli alla variabile $message?

<?PHP
    $query = "SELECT * FROM yourtable WHERE youridentifier = 'unique'"
    $result = mysql_query($query) or die(mysql_error());
    while ($row = mysql_fetch_array($result)) {
        $content = $row['field with email content']
        // or if there is more than one field
        $content2 = $row['field with more email content']
    }
    // then you can create the "message" as you wish
    $message = "Greetings ".$content.",

        you are receiving this email because of blah. ".$content2."

        Thank you,
        code guy"
    // Then you can still use $message as your variable
}
?>

formattalo come te con (HTML o no, ecc.) .. e spedisci via la posta.

per più righe cambia leggermente il tempo in alto..

<?PHP
    // give your message the starting string
    $message = 'Greetings,

        you are receiving this email as an invoice as follows:
        <table style="width: 80%;">
            <tr>
                <td>Description</td>
                <td>Cost</td>
                <td>Weight</td>
                <td>Color</td>
            </tr>
    '
    $query = "SELECT * FROM yourtable WHERE youridentifier = 'unique'"
    $result = mysql_query($query) or die(mysql_error());
    while ($row = mysql_fetch_array($result)) {
        $message .= "        <tr>";
        $message .= "            <td>".$row['itemdescription']."</td>";
        $message .= "            <td>".$row['cost']."</td>";
        $message .= "            <td>".$row['shippingweight']."</td>";
        $message .= "            <td>".$row['color']."</td>";
        $message .= "        </tr>";
    }
    // then update the message with the ending
    $message .= "
        </table>

        Thank you,
        code guy"
    // Then you can still use $message as your variable
}
?>

Tale presupposto è se stai utilizzando e-mail formattate in HTML, altrimenti sarà solo testo formattato.