누군가가 PHPmailer 코드 변환을 도울 수 있기를 바랍니다.php7로 서버 업그레이드로 인해 phpmailer6으로 변환, 네임 스페이스 오류
내가 길을 잃어 버렸고 잘못 가고있는 곳에서 해결할 수는 없지만 네임 스페이스와 파트를 사용하는 것처럼 보입니다. 필요한 페이지가 있지만 괜찮습니다. 네임 스페이스 및 사용 코드) 작동하지 않을 수 있습니다! 내가 바로 먼저 첫 번째 부분을 얻을 필요로
namespace MyProject;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require '/home/lanoil/public_html/libraries/php_mailer/phpmailer.php';
require '/home/lanoil/public_html/libraries/php_mailer/SMTP.php';
require '/home/lanoil/public_html/libraries/php_mailer/Exception.php';
$mail = new PHPMailer(true);
전체 페이지 코드는
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
define('_JEXEC', 1);
// this file is in a subfolder 'scripts' under the main joomla folder
define('JPATH_BASE', realpath(dirname(__FILE__) . '/..'));
require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';
// instantiate application
$app = JFactory::getApplication('site');
// database connection
$dbj = JFactory::getDbo();
// External database connection
JLoader::discover('Lanoil', JPATH_LIBRARIES . '/lanoil');
$config = new LanoilConfig();
$db = new LanoilDb();
if (isset($_POST['deadline'])) {
$deadline = ($_POST['deadline']/1000);
$db->query("update automate set deadline =".$deadline); // adding deadline to db for cron job.
$sql= "SELECT DISTINCT `email` FROM `tbl_clients` where `email` IS NOT NULL";
$stmt = $db->prepare($sql);
$stmt->execute();
$emails = array();
foreach($db->query($sql) as $row){
array_push($emails, $row['email']);
}
$test = implode(", ",$emails);
echo $test;
foreach($emails as $email){
$mail->AddBCC($email);
}
function url_get_contents ($Url) {
if (!function_exists('curl_init')){
die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
namespace MyProject;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require '/home/lanoil/public_html/libraries/php_mailer/phpmailer.php';
require '/home/lanoil/public_html/libraries/php_mailer/SMTP.php';
require '/home/lanoil/public_html/libraries/php_mailer/Exception.php';
$mail = new PHPMailer(true);
try {
//$mail->Host = "mail.yourdomain.com"; // SMTP server
//Create a new PHPMailer instance
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
$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 = "password"; // GMAIL password
$mail->AddReplyTo('[email protected]', 'Gordon Muir');
$mail->AddAddress('[email protected]', 'Gordon Muir');
$mail->SetFrom('[email protected]', 'Gordon Muir');
$mail->AddReplyTo('[email protected]', 'Gordon Muir');
$mail->Subject = 'Time to order your oil from the Rural Oil Club';
$mail->AltBody = 'This email is to alert you that it is now time to order your oil from the Rural Oil, Club'; // optional - MsgHTML will create an alternate automatically
$body = url_get_contents(page to call);
$mail->MsgHTML($body);
$mail->Send();
echo "Message Sent OK
<p></p>
\n";
} catch (Exception $e) {
echo $e->errorMessage();
} catch (\Exception $e) {
echo $e->getMessage();
}
// Publish Order Oil menu item
$query = $dbj->getQuery(true);
// Fields to update.
$fields = array(
$dbj->quoteName('published') . ' = 1'
);
// Conditions for which records should be updated.
$conditions = array(
$dbj->quoteName('id') . ' = 195'
);
$query->update($dbj->quoteName('#__menu'))->set($fields)->where($conditions);
$dbj->setQuery($query);
$result = $dbj->execute();
}
else
{
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$("#datepicker").datepicker({ dateFormat: "@" });
});
</script>
</head>
<body>
<form action="" method="post">
Deadline: <input type="text" name="deadline" id="datepicker"><br>
<input type="submit">
</form>
<?php }
?>
</body>
</html>
아직 메시지를 보내는 실제의 PHPmailer 코드 중 하나를 변경되지 않았습니다. (분명히 내가 프로가 아니기 때문에 코드는 깔끔하지 않을 것이다!)
모두 다 괜찮아 보입니다. 실제 발생한 오류를 게시하십시오. 아 ~'phpmailer.php'가 맞습니까? 원본은'PHPMailer.php'입니다. – Synchro