【问题标题】:send an email with mysql fetch records发送带有 mysql 获取记录的电子邮件
【发布时间】:2013-12-16 09:40:34
【问题描述】:

现在我想生成一张客户凭证,然后将其发送到特定人员的电子邮件 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数据)......

【问题讨论】:

    标签: php mysql email phpmailer


    【解决方案1】:
    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);
    

    【讨论】:

      【解决方案2】:
         <?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();
              ?>
      

      【讨论】:

      • 但我没有收到任何电子邮件..?
      • 你有没有使用phpmailer库?
      • 您是否更新了您的主机名、用户名、密码和 addAddress 电子邮件 ID?您是在本地主机还是服务器上使用此代码?
      • 您应该在服务器上尝试此代码。同时检查您的邮件是否会成为垃圾邮件。
      • 我更新了我的问题。再看看我的问题。我更改了与您的编码相关的编码..
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-11
      • 2014-08-02
      • 1970-01-01
      • 2021-10-06
      • 2015-09-09
      相关资源
      最近更新 更多