2013-11-30 3 views
0

Когда я отправляю страницу по электронной почте, она показывает код php. он не извлекает данные из mysql, а затем я извлекаю записи mysql на основе конкретного идентификатора ваучера. как отправить страницу записей mysql fetch по электронной почте? посмотрите на это кодирование.как отправить mysql fetch records php страницу по электронной почте

<?php 
require_once('phpmailer/class.phpmailer.php'); 
include("phpmailer/class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded 

$mail    = new PHPMailer(); 

$body    = file_get_contents('print.php[HERE HOW CAN I FETCH MYSQL RECORDS OF PARTICULAR VOUCHER ID]'); 
$body    = preg_replace('/\/b]/','',$body); 


$mail->IsSMTP(); // telling the class to use SMTP 
$mail->Host  = "smtp.gmail.com"; // SMTP server 
$mail->SMTPDebug = 1;      // enables SMTP debug information (for testing) 
              // 1 = errors and messages 
              // 2 = messages only 
$mail->SMTPAuth = true;     // enable SMTP authentication 
$mail->SMTPSecure = "tls";     // sets the prefix to the servier 
$mail->Host  = "smtp.gmail.com";  // sets GMAIL as the SMTP server 
$mail->Port  = 587;     // set the SMTP port for the GMAIL server 
$mail->Username = "[email protected]"; // Email username 
$mail->Password = "mypassword";   // Email password 

$mail->SetFrom('[email protected]', 'Subject Line'); 

$mail->AddReplyTo("[email protected]","Subject Line"); 

$mail->Subject = "Full Subject Line"; 

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 

$mail->MsgHTML($body); 

$email = $_POST['email']; 
$mail->AddAddress($email); 

if(!$mail->Send()) { 
    echo "<div align=center style=\"color:#FF0000; font-family: 'Times New Roman', Times, serif; font-size: 26px;\">Could not send email to : . $mail->ErrorInfo</div>"; 
} else { 
    echo "<script> alert('Mail successfully sent to $email') </script>"; 
    echo '<META HTTP-EQUIV="Refresh" Content="0; URL=mainpage.php">'; 
    exit; 
} 
?> 

Я хочу получить данные mysql здесь на основе конкретного идентификатора ваучера. если пользователь щелкнет идентификатор ваучера 10, он отобразит полную информацию о идентификаторе ваучера 10. а затем я хочу отправить эту страницу по электронной почте. теперь я получил электронное письмо. но я не получил записи mysql этого конкретного идентификатора. как это сделать?

ответ

1

У меня был другой вопрос здесь (send an email with mysql fetch records). Я получил помощь от этой должности. поэтому, я разместил правильный ответ ниже.

<?php 
ob_start(); 
require_once('phpmailer/class.phpmailer.php'); 
include("phpmailer/class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded 

$mail    = new PHPMailer(); 

$mail->IsSMTP(); // telling the class to use SMTP 
$mail->Host  = "smtp.gmail.com"; // SMTP server 
$mail->SMTPDebug = 1;      // enables SMTP debug information (for testing) 
              // 1 = errors and messages 
              // 2 = messages only 
$mail->SMTPAuth = true;     // enable SMTP authentication 
$mail->SMTPSecure = "tls";     // sets the prefix to the servier 
$mail->Host  = "smtp.gmail.com";  // sets GMAIL as the SMTP server 
$mail->Port  = 587;     // set the SMTP port for the GMAIL server 
$mail->Username = "[email protected]"; // GMAIL username 
$mail->Password = "mypassword";   // GMAIL password 

include("config.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); 
     $strMessage = "<table> 
    <tr> 
<td>Voucher Number : </td> 
<td> $row->voucherno </td> 
<td>Reference Number : </td> 
<td> $row->reference </td> 
    </tr> 
    </table>"; 

$mail->SetFrom('[email protected]', 'FromName'); 

$email = mysql_real_escape_string($_POST['email']); 
$mail->AddAddress($email ,"$row->gname, $row->city"); 
$mail->Subject = "Subject Line"; 

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 

$mail->Body = $strMessage; 

if($mail->Send()) 
     { 
     echo "<script> alert('Mail succesfully sent to $email.'); </script>."; 
     echo '<META HTTP-EQUIV="Refresh" Content="0; URL=mainpage.php">'; 
     exit; 
     } 
     else 
     { 
     echo "<div align=center style=\"color:#FF0000; font-family: 'Times New Roman', Times, serif; font-size: 26px;\"> Cannot send mail. $mail->ErrorInfo. </div>"; 
     } 
     } 
ob_flush(); 
?> 
Смежные вопросы