fixing E-Mail
This commit is contained in:
parent
a2c4e969ff
commit
3565c271d4
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPMailer Exception class.
|
||||
* PHP Version 5.5.
|
||||
*
|
||||
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
|
||||
*
|
||||
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
|
||||
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
|
||||
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
|
||||
* @author Brent R. Matzelle (original founder)
|
||||
* @copyright 2012 - 2020 Marcus Bointon
|
||||
* @copyright 2010 - 2012 Jim Jagielski
|
||||
* @copyright 2004 - 2009 Andy Prevost
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
* @note This program is distributed in the hope that it will be useful - WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
namespace PHPMailer\PHPMailer;
|
||||
|
||||
/**
|
||||
* PHPMailer exception handler.
|
||||
*
|
||||
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
|
||||
*/
|
||||
class Exception extends \Exception
|
||||
{
|
||||
/**
|
||||
* Prettify error message output.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function errorMessage()
|
||||
{
|
||||
return '<strong>' . htmlspecialchars($this->getMessage()) . "</strong><br />\n";
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -2,12 +2,18 @@
|
|||
include "zefixAPI.php";
|
||||
include "read_write_xlsx.php";
|
||||
|
||||
require_once "PHPMailer.php";
|
||||
require_once "SMTP.php";
|
||||
require_once "Exception.php";
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
$maxExecutionTime = 300;
|
||||
$taskDir = 'tasks';
|
||||
$downloadDir = 'download';
|
||||
$minTaskOldness = 30;
|
||||
$latesEndTime = time() + $maxExecutionTime;
|
||||
|
||||
$smtppassword = getenv("smtppassword");
|
||||
|
||||
if(!is_dir($downloadDir)){
|
||||
mkdir($downloadDir, 0755, true);
|
||||
|
@ -43,22 +49,36 @@ function doRequest($data, $filename, $username, $password)
|
|||
|
||||
|
||||
|
||||
function sendEmail($emailAddress, $filename)
|
||||
function sendEmail($emailAddress, $filename, $smtppassword)
|
||||
{
|
||||
echo "sending ".$filename." too ".$emailAddress;
|
||||
$to = $emailAddress;
|
||||
$subject = "Ihr Export von Zefix ist bereit";
|
||||
$message = "Nutzen Sie den folgenden Link um ihre Daten herunterzuladen. Die Daten werden nach 48 Stunden automatisch von unserem Server gelöscht.\nhttps://zefix.silias.ch/".$filename;
|
||||
$headers = "From: api@zefix.silias.ch\r\n";
|
||||
$headers .= "Reply-To: info@silias.ch\r\n";
|
||||
$headers .= "MIME-Version: 1.0\r\n";
|
||||
$headers .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
|
||||
$mail = new PHPMailer();
|
||||
|
||||
if (mail($to, $subject, $message, $headers)) {
|
||||
echo "Email sent successfully!";
|
||||
} else {
|
||||
echo "Email sending failed.";
|
||||
$mail->isSMTP(); // Set mailer to use SMTP
|
||||
$mail->Host = 'smtp.titan.email; smtp.titan.email'; // Specify main and backup SMTP servers
|
||||
$mail->SMTPAuth = true; // Enable SMTP authentication
|
||||
$mail->Username = 'api@zefix.silias.ch'; // SMTP username
|
||||
$mail->Password = $smtppassword; // SMTP password
|
||||
$mail->SMTPSecure = 'SSL'; // Enable TLS encryption, `ssl` also accepted
|
||||
$mail->Port = 465; // TCP port to connect to
|
||||
|
||||
$mail->isHTML(true);
|
||||
$mail->setFrom('web@silias.ch', 'Silias Zefix Export');
|
||||
$mail->addAddress($emailAddress);
|
||||
$mail->addReplyTo('info@silias.ch', 'Silias KLG');
|
||||
$mail->Subject = 'Ihr Export von Zefix ist bereit';
|
||||
$mail->Body = 'Nutzen Sie den folgenden Link um ihre Daten herunterzuladen. Die Daten werden nach 48 Stunden automatisch von unserem Server gelöscht.\n<a href="https://zefix.silias.ch/'.$filename.'">https://zefix.silias.ch/'.$filename.'</a>';
|
||||
|
||||
if($mail->send()){
|
||||
$status = "success";
|
||||
$response = "Email is sent!";
|
||||
}
|
||||
else{
|
||||
$status = "failed";
|
||||
$response = "Something is wrong: <br>" . $mail->ErrorInfo;
|
||||
}
|
||||
|
||||
echo "Email status:".$status;
|
||||
echo "Email Response:".$response;
|
||||
}
|
||||
// Stop executing bevore reaching PHP Max Execution Time
|
||||
function convertcsvToXlsx(string $csvFile, string $xlsxFile)
|
||||
|
@ -105,7 +125,7 @@ while($latesEndTime - time() > 60){
|
|||
else {
|
||||
convertcsvToXlsx(str_replace(".json", ".csv", $downloadDir.'/'.$taskfiles[0]), str_replace(".json", ".xlsx", $downloadDir.'/'.$taskfiles[0]));
|
||||
unlink(str_replace(".json", ".csv", $downloadDir.'/'.$taskfiles[0]));
|
||||
sendEmail($task['email'], str_replace(".json", ".xlsx", $downloadDir.'/'.$taskfiles[0]));
|
||||
sendEmail($task['email'], str_replace(".json", ".xlsx", $downloadDir.'/'.$taskfiles[0]), $smtppassword);
|
||||
unlink($taskDir.'/'.$taskfiles[0]);
|
||||
echo "Task File deleted";
|
||||
echo "<br>";
|
||||
|
|
|
@ -4,7 +4,6 @@ $username = getenv("username");
|
|||
$password = getenv("password");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param string $
|
||||
* @param string $
|
||||
|
|
Loading…
Reference in New Issue