Autor | Zpráva | ||
---|---|---|---|
peter_r Profil |
#1 · Zasláno: 25. 1. 2022, 10:17:21
Zdravím, prosím o radu, skúšam všetko a stále zle. Našiel som super návod na vytvorenie PDF a odoslanie na email ako prílohu, je to zo stránky www.webslesson.info/2018/08/create-dynamic-pdf-send-as-attachment-with-email-in-php.html a funguje to. Ale to je výpis celej tabuľky, ja potrebujem len výpis určitého riadku z tabuľky, toto som tiež zvládol, zmenil som toto:
$query = "SELECT * FROM tbl_customer WHERE tbl_id=" .intval($_GET['mat_id']); vypíše mi len zvolený riadok z tabuľky čo je všetko OK ale chcem aby pri odosielaní mi ako predmet uviedlo $row["CustomerName"] takže mením toto: $mail->Subject = 'Customer Details'; skúšal som hocičo ale nepomáha: $mail->Subject = $row["CustomerName"]; aj úvodzovky ale stále nič, Ďakujem za rady |
||
Kajman Profil |
#2 · Zasláno: 25. 1. 2022, 10:29:38
Vypište si obsah $row. Např.
print_r($row); Zkontrolujte si tam název klíče, zda přesně souhlasí včetně velikosti písmen. |
||
peter_r Profil |
Kajman:
názov je správny skúšal som do predmetu dať $file_name a vtedy to zoberie $file_name = md5(rand()) . '.pdf'; $mail->Subject = ($file_name); ale názov súboru je nejakých 20 náhodných písmen a čísel, čo nechcem, tak som zmenil $file_name = md5(rand()) . '.pdf'; na $file_name = $row["CustomerName"] . '.pdf'; ale aj tak nič |
||
Keeehi Profil |
#4 · Zasláno: 25. 1. 2022, 12:19:28
Nech tam to "náhodné jméno" a název souboru změň až při posílání emailu.
$mail->AddAttachment($file_name, $row["CustomerName"] . '.pdf'); |
||
peter_r Profil |
#5 · Zasláno: 26. 1. 2022, 11:20:25
Keeehi:
neberie to Notice: Undefined variable: row in C:\xampp\htdocs\pdf\index2.php on line 71 to je ten riadok proste to $row["CustomerName"] nepozná |
||
Keeehi Profil |
#6 · Zasláno: 26. 1. 2022, 11:43:07
<?php //index.php $message = ''; $connect = new PDO("mysql:host=localhost;dbname=testing", "root", ""); function fetch_customer_data($connect) { $query = "SELECT * FROM tbl_customer WHERE tbl_id=" .intval($_GET['mat_id']) ." LIMIT 1"; $statement = $connect->prepare($query); $statement->execute(); return $statement->fetch(PDO::FETCH_ASSOC); } function generate_table($row) return ' <div class="table-responsive"> <table class="table table-striped table-bordered"> <tr> <th>Name</th> <th>Address</th> <th>City</th> <th>Postal Code</th> <th>Country</th> </tr> <tr> <td>'.$row["CustomerName"].'</td> <td>'.$row["Address"].'</td> <td>'.$row["City"].'</td> <td>'.$row["PostalCode"].'</td> <td>'.$row["Country"].'</td> </tr> </table> </div> '; } $data = fetch_customer_data($connect); if(isset($_POST["action"])) { include('pdf.php'); $file_name = md5(rand()) . '.pdf'; $html_code = '<link rel="stylesheet" href="bootstrap.min.css">'; $html_code .= generate_table($data); $pdf = new Pdf(); $pdf->load_html($html_code); $pdf->render(); $file = $pdf->output(); file_put_contents($file_name, $file); require 'class/class.phpmailer.php'; $mail = new PHPMailer; $mail->IsSMTP(); //Sets Mailer to send message using SMTP $mail->Host = 'smtpout.secureserver.net'; //Sets the SMTP hosts of your Email hosting, this for Godaddy $mail->Port = '80'; //Sets the default SMTP server port $mail->SMTPAuth = true; //Sets SMTP authentication. Utilizes the Username and Password variables $mail->Username = 'xxxxxxxxxx'; //Sets SMTP username $mail->Password = 'xxxxxxxxxx'; //Sets SMTP password $mail->SMTPSecure = ''; //Sets connection prefix. Options are "", "ssl" or "tls" $mail->From = 'info@webslesson.info'; //Sets the From email address for the message $mail->FromName = 'Webslesson.info'; //Sets the From name of the message $mail->AddAddress('web-tutorial@programmer.net', 'Name'); //Adds a "To" address $mail->WordWrap = 50; //Sets word wrapping on the body of the message to a given number of characters $mail->IsHTML(true); //Sets message type to HTML $mail->AddAttachment($file_name, $data['CustomerName']); //Adds an attachment from a path on the filesystem $mail->Subject = 'Customer Details'; //Sets the Subject of the message $mail->Body = 'Please Find Customer details in attach PDF File.'; //An HTML or plain text message body if($mail->Send()) //Send an Email. Return true on success or false on error { $message = '<label class="text-success">Customer Details has been send successfully...</label>'; } unlink($file_name); } ?> <!DOCTYPE html> <html> <head> <title>Create Dynamic PDF Send As Attachment with Email in PHP</title> <script src="jquery.min.js"></script> <link rel="stylesheet" href="bootstrap.min.css" /> <script src="bootstrap.min.js"></script> </head> <body> <br /> <div class="container"> <h3 align="center">Create Dynamic PDF Send As Attachment with Email in PHP</h3> <br /> <form method="post"> <input type="submit" name="action" class="btn btn-danger" value="PDF Send" /><?php echo $message; ?> </form> <br /> <?php echo generate_table($data); ?> </div> <br /> <br /> </body> </html> |
||
peter_r Profil |
Keeehi:
riadok 18 mi vypisuje chybu Parse error: syntax error, unexpected 'return' (T_RETURN), expecting '{' in C:\xampp\htdocs\pdf\index2.php on line 18 chýbal tam začiatok zátvorky { return ' a súbor prišiel bez koncovky pdf tak som to opravil takto a je to ok $mail->AddAttachment($file_name, $data['nazov'] . '.pdf'); tak prosím o kontrolu, ale keďže to funguje tak by to malo byť ok ale, je to len začiatok, chcel som to pochopiť a teraz hlavne potrebujem vytiahnuť z tabuľky emailovú adresu na ktorú sa má ten email odoslať, tak som zvedavý či to zvládnem, ak nie tak budem písať zatiaľ veľmi pekne ďakujem |
||
peter_r Profil |
#8 · Zasláno: 28. 1. 2022, 11:29:16
Tak som to zvládol, ale samozrejme jeden problém tam musel nastať a to je kódovanie.
Pred vytvorením pdf mi diakritiku zobrazuje správne: ľščťžýáíé ale na email príde pdf už na prd: ?š??žýáíé v databáze mám nastavené kódovanie utf8_czech_ci (neviem prečo práve také) skontrolovať som súbor, ktorý pravdepodobne vytvára pdf, našiel som tam len toto (ten súbor má 3000 riadkov tak ho tu nechcem dávať celý): public $CharSet = 'iso-8859-1'; /** * Sets the Content-type of the message. * @var string */ public $ContentType = 'text/plain'; /** * Sets the Encoding of the message. Options for this are * "8bit", "7bit", "binary", "base64", and "quoted-printable". * @var string */ public $Encoding = '8bit'; čo mám zmeniť aby to bolo OK? ďakujem |
||
Kajman Profil |
#9 · Zasláno: 28. 1. 2022, 11:52:56
iso-8859-1 nepodporuje české znaky, zkuste iso-8859-2.
Případně utf-8, ale to byste musel možná změnit i Encoding na "base64" nebo "quoted-printable". Ale nejsem si jistý, kde máte diakritiku špatně, zda v pdf nebo jen v textu emailu. |
||
peter_r Profil |
Kajman:
diakritika je zlá aj v pdf aj v texte emailu, v texte by mi ani tak nevadila ale pdf musí byť správna skúsil som zatiaľ iso-8859-2 ale nič peter_r: pri zmene na UTF-8 už text správy je OK ale pdf stále nič, a to som skúsil zmeniť Encoding na všetky uvedené typy |
||
peter_r Profil |
Pomohlo by, keby som zmenil kódovanie v databáze na niečo iné?
|
||
Kajman Profil |
#12 · Zasláno: 28. 1. 2022, 15:03:38
A font jste si nastavil díky css v html dle doporučení?
github.com/dompdf/dompdf |
||
Časová prodleva: 3 dny
|
|||
peter_r Profil |
#13 · Zasláno: 31. 1. 2022, 07:31:52
Ďakujem za radu, aj keď som to sťahoval z inej stránky a nie je to celkom rovnaké, môže na to niečo byť.
Ale môžete mi poradiť, kde a aký mám ten font nastaviť? V ktorom css? The PDF specification requires that PDF readers support a core set of fonts. These fonts are as follows: Courier (Normal, Bold, Oblique, and BoldOblique variants) Helvetica (Normal, Bold, Oblique, and BoldOblique variants) Times (Normal, Bold, Oblique, and BoldOblique variants) Symbol ZapfDingbats These fonts only support Windows ANSI encoding. In order for a PDF to display characters that are not available in Windows ANSI you must supply an external font, which will be embedded in the PDF. dompdf will embed any referenced true-type font in the PDF that has been pre-loaded or is referenced in a CSS @font-face rule. Dompdf supports the same fonts as the underlying R&OS PDF class: Type 1 (.pfb) and TrueType (.ttf) so long as the font metrics (.afm/.ufm) are available. The bundled, PHP-based php-font-lib provides support for loading and sub-setting fonts. As of dompdf 0.6.0 the DejaVu TrueType fonts have been pre-installed to give dompdf decent Unicode character coverage by default. To use the DejaVu fonts remember to reference the font in your stylesheet, e.g. body { font-family: DejaVu Sans; } (for DejaVu Sans). |
||
peter_r Profil |
#14 · Zasláno: 31. 1. 2022, 09:24:42
nepomáha nič, som stratený :-(
|
||
Kajman Profil |
#15 · Zasláno: 31. 1. 2022, 09:49:08
Do proměnné $html_code si dáváte html kód stránky, která se má převést do pdf. V tomto html kódu zadefinujte, že je obsah v utf-8 (pokud tomu tak je) a že se má použít font, který je v tom generátoru pdf předpřipravený k vložení do pdf.
Něco jako $html_code = '<!doctype html> <meta charset="utf-8"> <title>Nadpis PDF</title> <link rel="stylesheet" href="bootstrap.min.css"> <style>* { font-family: DejaVu Sans !important; }</style>'; $html_code .= generate_table($data); |
||
peter_r Profil |
#16 · Zasláno: 31. 1. 2022, 10:17:59
Ďakujem veľmi pekne, ste profík, môžem sa nejako revanšovať? odmeniť?
|
||
Časová prodleva: 2 roky
|
0