-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php.save
More file actions
75 lines (61 loc) · 2.4 KB
/
functions.php.save
File metadata and controls
75 lines (61 loc) · 2.4 KB
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
<?php
if(!defined('INCLUDE_CHECK')) die('You are not allowed to execute this file directly');
include_once('class.phpmailer.php');
function checkEmail($str)
{
return preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);
}
function send_mail($from,$to,$subject,$body)
{
$headers = '';
$headers .= "From: $from\n";
$headers .= "Reply-to: $from\n";
$headers .= "Return-Path: $from\n";
$headers .= "Message-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Date: " . date('r', time()) . "\n";
mail($to,$subject,$body,$headers);
}
?>
<?php
/********************* included files ****************************/
include_once('include/class.phpmailer.php');
include_once ('include/neoteric_general.inc');
include_once('include/neoteric_globals.inc.php');
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SendMail transport
$url = urldecode(getValue('pageToPrint') . '&offset=5&NEOPASSWD=' . MD5(NEOPASSWD));
try {
$mail->AddAddress(getValue('to'));
$mail->SetFrom(getValue('from'));
$mail->Subject = getValue('subject');
$mail->MsgHTML(getValue('message'));
if(!file_exists(EMAIL_TMP)) mkdir(EMAIL_TMP);
$basefile = $file = 'srfax_html2pdf';
while(file_exists(EMAIL_TMP . '/' . $file . '.html')) $file = $basefile . ($index = rand(0,10000));
//while(file_exists(EMAIL_TMP . '/' . $file . '.html')) $file = $basefile . ($index = 2261);
$htmlfile = EMAIL_TMP . '/' . $file . '.html';
$pdffile = EMAIL_TMP . '/' . $file . '.pdf';
$fh = fopen($url, "rb");
$html = '';
$html = implode('', file($url));
fclose($fh);
$fh = fopen($htmlfile, 'w');
fwrite($fh, $html);
fclose($fh);
$cmd = "convert -antialias -contrast -density 300 $htmlfile $pdffile";
if(file_exists($htmlfile))
exec($cmd);
else
throw new Exception('HTML file not created');
$mail->AddAttachment($pdffile); // attachment
$mail->Send();
echo "The email was sent successfully";
} catch (phpmailerException $e) {
echo "The email was not sent successfully<hr/>";
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo "The email was not sent successfully<hr/>";
echo $e->getMessage(); //Boring error messages from anything else!
}
?>