-
Notifications
You must be signed in to change notification settings - Fork 0
/
send.php
85 lines (60 loc) · 1.83 KB
/
send.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
require ('content/fonctions.php');
include ('config.php');
include ('include/langue.php');
/*
* include ('langs/fr.php');
* include ('class/class.php');
*/
/* librairie mpdf version 7 */
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once 'vendor/autoload.php';
$filename = "article.pdf";
/* si le pdf existe, on le supprime */
if (file_exists ( $filename )) {
unlink ( $filename );
}
/* Génération du pdf de l'article */
$sqlArticle = "SELECT * FROM articles WHERE publication ='1' AND ref='".$_GET['id']."'";
$reqArticle = $pdo->prepare($sqlArticle);
$reqArticle->execute();
while ($data = $reqArticle->fetch(PDO::FETCH_ASSOC)) {
$mpdf = new \Mpdf\Mpdf();
$stylesheet = file_get_contents ('style/style.css');
$mpdf->WriteHTML ($stylesheet, 1 );
$mpdf->WriteHTML ("<h1>".$data['titre']."</h1>".$data ['article'], 2);
$mpdf->Output ($filename);
}
/* envoi du pdf par mail avec PHPMailer */
$mail = new PHPMailer ();
/* TODO : Serveur SMTP */
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'alexis.amand@gmail.com';
$mail->Password = '......'; /* TODO : j'ai supprimé le mdp pour la mise sur GitHub*/
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
/* non recommandé : ça allow insecure connections */
$mail->SMTPOptions = array (
'ssl' => array (
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
/* Expéditeur */
$mail->SetFrom ( 'alexis.amand@gmail.com', 'Expéditeur' );
/* Destinataire */
$mail->AddAddress ( 'alexis.amand@gmail.com' );
/* Contenu */
$mail->IsHTML ( true );
$mail->CharSet = "utf-8";
$mail->Subject = 'Essai pour publiGED';
$mail->Body = '<p><b>E-Mail</b> au format <i>HTML</i>.</p>';
$mail->AddAttachment ( './' . $filename );
/* Envoi */
$mail->Send ();
?>