2017-10-23 12 views
0

누군가가 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 코드 중 하나를 변경되지 않았습니다. (분명히 내가 프로가 아니기 때문에 코드는 깔끔하지 않을 것이다!)

+0

모두 다 괜찮아 보입니다. 실제 발생한 오류를 게시하십시오. 아 ~'phpmailer.php'가 맞습니까? 원본은'PHPMailer.php'입니다. – Synchro

답변

1

쉬운 오류 : namespace은 다른 스크립트보다 먼저 파일에서 가장 먼저해야 할 일이며, 상단에도 use 줄이 있습니다. 그것은 당신이 받고있는 오류가 될 것입니다. 이 내용은 the PHP namespace docs에 있습니다.

+0

이제 다음과 같은 오류가 발생합니다 : 오류 페이지 표시 오류 : 응용 프로그램 인스턴스화 오류 : 'MyProject \ JFactory'클래스가 없습니다. – ruraldev

+0

여러분이 'MyProject' 네임 스페이스를 선언했지만'JFactory' 클래스를 사용할 수 없습니다 해당 네임 스페이스에 있습니다. 완전히 네임 스페이스 ('namespace') 지시어가 전혀 필요 없다. 삭제를 시도해라. PHPMailer에 여전히'use' 지시어가 필요합니다. – Synchro

+0

네임 스페이스를 삭제하면 완전히 다른 것과 관련된 것처럼 보이는 이러한 오류가 발생합니다! 경고 : require_once (/home/lanoil/public_html/libraries/joomla/document/html/renderer/head.php) : 스트림을 열지 못했습니다./home/lanoil/public_html/templates/rt_iridescent/error에 해당 파일이나 디렉토리가 없습니다. php on line 141 치명적인 오류 : require_once() : 개봉 실패 '/home/lanoil/public_html/libraries/joomla/document/html/renderer/head.php'(include_path = '. :/opt/cpanel/ea -php70/root/usr/share/pear ') /home/lanoil/public_html/templates/rt_iridescent/error.php on line 121 – ruraldev