发送多封来自数据库的不同内容的电子邮件?

时间:2014-03-08 13:30:19

标签: php mysql

我可以使用相同的图片发送两封电子邮件,但不能发送存储在MySQL表中的所需MySQL数据ab。两封电子邮件中只显示了相同的数据a

如何发送包含不同数据的每封电子邮件,即第一个数据a和第二个b

这是我的代码:

<?php
$con=mysqli_connect("localhost","586729","xxxxxxxx","586729");
// Check connection
if (mysqli_connect_errno())
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$i=1;
$result = mysqli_query($con,"SELECT * FROM db");
while($row = mysqli_fetch_array($result))
{
    $s[$i] = $row['sch name'];
    $i=$i+1;
}
mysqli_close($con);

$i=2;
while($i>=1)
{
    $to = 'woshicdg@gmail.com';
    $subject = 'PHP Mail Attachment Test';
    $bound_text = "jimmyP123";
    $bound = "--".$bound_text."\r\n";
    $bound_last = "--".$bound_text."--\r\n";

    $headers = "From: admin@server.com\r\n";
    $headers .= "MIME-Version: 1.0\r\n"
             ."Content-Type: multipart/mixed; boundary=\"$bound_text\"";

    $message .= "If you can see this MIME than your client doesn't accept MIME types!\r\n"
             .$bound;

    $message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
             ."Content-Transfer-Encoding: 7bit\r\n\r\n"
             ."The short form of the school name ".$s[$i]." is shown now.\r\n"
             .$bound;

    $file = file_get_contents("http://hkalextsui.freevar.com/machu.JPG");

    $message .= "Content-Type: image/jpg; name=\"regal_004.jpg\"\r\n"
             ."Content-Transfer-Encoding: base64\r\n"
             ."Content-disposition: attachment; file=\"regal_004.jpg\"\r\n"
             ."\r\n"
             .chunk_split(base64_encode($file))
             .$bound_last;

    if(mail($to, $subject, $message, $headers))
    {
        echo 'MAIL SENT';
    }
    else
    {
        echo 'MAIL FAILED';
    }
    $i=$i-1;
}
?> 

0 个答案:

没有答案