send an email with mysql fetch records

守給你的承諾、 提交于 2019-12-08 06:35:46

问题


now i want to generate a customer voucher and then send it to particular person email id. i have done the basic mail function using phpmailer. now, i received an email but i did not get the mysql datas. i tried something. but its not working. for example if i am clicking the voucher id 7 then it will show the full details of voucher id 7. i want to send that particular (voucher id 7) datas to an email.

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

here how can i insert mysql_fetch records into email body page...? i hope anyone tell me the answer for this one..

this is my print.php page coding :

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>
}

still lot of datas i'm fetching from mysql db. so i want to send an email this page (including mysql datas)...


回答1:


   <?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();
        ?>



回答2:


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);


来源:https://stackoverflow.com/questions/20298515/send-an-email-with-mysql-fetch-records

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!