发送带有mysql获取记录的电子邮件

时间:2013-11-30 09:14:25

标签: php mysql email phpmailer

现在我想生成一个客户代金券,然后将其发送给特定的人员电子邮件ID。我已经使用phpmailer完成了基本的邮件功能。现在,我收到了一封电子邮件,但我没有得到mysql数据。我试了一下。但它不起作用。例如,如果我点击凭证ID 7,那么它将显示凭证ID 7的完整详细信息。我想将特定的(凭证ID 7)数据发送到电子邮件。

$body = file_get_contents('print.php');

这里如何将mysql_fetch记录插入电子邮件正文页面?我希望有人能告诉我这个问题的答案。

这是我的print.php页面编码:

if(isset($_GET['id']))
{
    $id = mysql_real_escape_string($_GET['id']);
    $query = mysql_query ( "SELECT * FROM voucher WHERE voucherno = $id" );
    $row = mysql_fetch_object($query);
    echo mysql_error();

<tr>
    <td width=193 height=40 class=rightstyle>Voucher Number : </td>
    <td width=229 class=leftstyle> $row->voucherno </td>
    <td width=234 class=rightstyle>Reference Number : </td>
    <td width=234 class=leftstyle> $row->reference </td>
  </tr>
}

我从mysql db获取的数据仍然很多。所以我想发送这个页面的电子邮件(包括mysql数据)......

2 个答案:

答案 0 :(得分:4)

   <?php
        ob_start();
        //smtp detail start
        require_once ('class.phpmailer.php' );
        $mail=new PHPMailer();
        $mail->IsSMTP(); // telling the class to use SMTP

        $mail->SMTPAuth   = true;                  // enable SMTP authentication

        //SMTP detail from here 
        //$mail->SMTPSecure = "ssl";
        $mail->Host       = "yourhostname";      // sets GMAIL as the SMTP server
        $mail->Port       = 25;                   // set the SMTP port for the GMAIL server
        $mail->Username   = "you@yourdomain.com";  
        $mail->Password   = "yourpassword";    
        //$mail->SMTPDebug=1;
        //SMTP deatil end
        //smtp mail end
    if(isset($_GET['id']))
    {    
    $id = mysql_real_escape_string($_GET['id']);
    $query = mysql_query ( "SELECT * FROM voucher WHERE voucherno = $id" );
    while($row = mysql_fetch_object($query))
        {    
        $strMessage = "<tr>
        <td width=193 height=40 class=rightstyle>Voucher Number : </td>
        <td width=229 class=leftstyle> $row->voucherno </td>
        <td width=234 class=rightstyle>Reference Number : </td>
        <td width=234 class=leftstyle> $row->reference </td>
      </tr>";
    }

       // $flgSend = @mail($strTo,$strSubject,$strMessage,$strHeader);  // @ = No show error //  
        $mail->FromName = "your name";
        $mail->From = "your mail id";
        $mail->ContentType ="text/html";
        $mail->AddAddress('test@testing.com');//mail will be send on this email
        $mail->Subject='customer voucher';      
        $mail->Body = $strMessage;

        if($mail->Send())
        {
        echo "mail send.";
        }  
        else  
        {  
        echo "Cannot send mail.";  
        }
        } 
        ob_flush();
        ?>

答案 1 :(得分:0)

Try this......
$check=mysql_query("SELECT * FROM tbl_user WHERE uid='$_SESSION[uid]'");
$percent=mysql_fetch_assoc($check);
$email=$percent['email'];
$to = "$email";
$subject = "Subject";
$message = "
<html>
<head>
<title>Request</title>
</head>
<body>
<font size='20px'>Hello </font>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From:Your email id' . "\r\n";
mail($to,$subject,$message,$headers);