誰かがPHPmailerコードの変換を手伝ってくれることを願っています。php7へのサーバのアップグレードによるphpmailer6への変換、名前空間エラー
私は少し失われてしまい、どこが間違っているのか分かりませんが、名前空間と使用部分のようですが、次のようなことがありますが、必要なページはOKです名前空間と使用コード)私はそれを動作させることはできません!私は右の最初の最初の部分を取得する必要があるとして、
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);
FULLページのコードが
<?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