Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Angularjs在HTML中调用PHP文件函数_Javascript_Php_Html_Angularjs - Fatal编程技术网

Javascript 使用Angularjs在HTML中调用PHP文件函数

Javascript 使用Angularjs在HTML中调用PHP文件函数,javascript,php,html,angularjs,Javascript,Php,Html,Angularjs,我有一个关于我们的一个项目的问题,这个项目是由另一个精通angular js的开发人员开发的,我不是。因此,问题概述如下: 我们有一个每天使用cron运行的报告,它是在PHP中直接调用的,现在有时服务器端数据库会关闭,我们必须手动运行该报告 我有一个HTML文件,可以用来制作按钮,但我不能直接在其中使用PHP函数。此项目中创建的所有其他HTML都使用angular js控制器。我只是想知道是否有办法让PHP函数在HTML中运行。我可以通读angularjs,但是有所有的post数据,我看不到获取

我有一个关于我们的一个项目的问题,这个项目是由另一个精通angular js的开发人员开发的,我不是。因此,问题概述如下: 我们有一个每天使用cron运行的报告,它是在PHP中直接调用的,现在有时服务器端数据库会关闭,我们必须手动运行该报告

我有一个HTML文件,可以用来制作按钮,但我不能直接在其中使用PHP函数。此项目中创建的所有其他HTML都使用angular js控制器。我只是想知道是否有办法让PHP函数在HTML中运行。我可以通读angularjs,但是有所有的post数据,我看不到获取get函数的方法。我在网上读了很多书,但一无所获

如果有人给我指出正确的方向,我将非常感激

我正在寻找angularJS成功回调的正确语法,然后用HTML调用它

PS:如果我问了一个多余的问题,而不仅仅是给我一个负面的名声,请让我知道

例如:

PHP:public\u html/XXXX/XXXX/PHP/cronHourly.PHP

function sendMyEmail($receiverName,$receiverEmail,$mySubject,$myMessage,$senderName,$senderEmail){
    //global $company,$companyPhone,$defaultEmail,$domain,$shopAddress,$stationeryPrefix,$siteStatus,$reportArray,$Host,$Port,$Username,$Password,$serverRoot;
$stationeryHeader = "<body bgcolor='#cccccc' leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'><style>
body {
      font-family: Arial;
       font-size: 12pt;
}
</style>
<br>
<table id='Table_01' border='0' cellpadding='0' align='center' bgcolor='#FFFFFF' width='800'>

<tr><td width='20'></td><td><br>";

$stationeryFooter = "</td><td width='20'></td></tr>

</table></body>";

    //$mail = new PHPMailer();
     $mail = new PHPMailer(true);

    $mail->IsHTML(true);
    $mail->isSMTP();  // tell the class to use SMTP
    $mail->SMTPAuth   = true; 
    //$mail->SMTPSecure  = "ssl"; //Secure conection
    $mail->Host = 'xxxx.com';
    $mail->Port = 00;
    $mail->Username = 'postmaster@xxx.xom';  // SMTP username
    $mail->Password = ''; // SMTP password
    $mail->From = 'postmaster@xxx.com';
    $mail->FromName = $senderName;
    $mail->AddReplyTo($senderEmail, $senderName); 
    $mail->AddAddress($receiverEmail, $receiverName);//send a copy to the client
    $mail->Subject = $mySubject;
    $mail->WordWrap = 80;
    $mail->AddEmbeddedImage('x.png', 'csvimg', 'csv.png'); // attach file logo.jpg, and later link to it using identfier logoimg
    //$mail->AddEmbeddedImage($serverRoot.'/images/'.$stationeryPrefix.'Header.jpg', $stationeryPrefix.'Header', $stationeryPrefix.'Header.jpg');
    //$mail->AddEmbeddedImage($serverRoot.'/images/'.$stationeryPrefix.'Footer.jpg', $stationeryPrefix.'Footer', $stationeryPrefix.'Footer.jpg');
    //$headerImage = $serverRoot.'/images/'.$stationeryPrefix.'Header.jpg';
    $mail->Body = $stationeryHeader;
    $mail->Body .= $myMessage;
    $mail->Body .= $stationeryFooter;
    if(!$mail->Send()){
        echo '<br />Message FAILED to '.$receiverEmail;
        '.$reportArray[1],$company,$defaultEmail);
    }else{
        echo '<br />Message successfully sent to '.$receiverEmail;
    }//end if mail>send
}//end function sendMyEmail


?>
function sendMyEmail($receiverName,$receiverEmail,$mySubject,$myMessage,$senderName,$senderEmail){
    //global $company,$companyPhone,$defaultEmail,$domain,$shopAddress,$stationeryPrefix,$siteStatus,$reportArray,$Host,$Port,$Username,$Password,$serverRoot;
$stationeryHeader = "<body bgcolor='#cccccc' leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'><style>
body {
      font-family: Arial;
       font-size: 12pt;
}
</style>
<br>
<table id='Table_01' border='0' cellpadding='0' align='center' bgcolor='#FFFFFF' width='800'>

<tr><td width='20'></td><td><br>";

$stationeryFooter = "</td><td width='20'></td></tr>

</table></body>";

    //$mail = new PHPMailer();
     $mail = new PHPMailer(true);

    $mail->IsHTML(true);
    $mail->isSMTP();  // tell the class to use SMTP
    $mail->SMTPAuth   = true; 
    //$mail->SMTPSecure  = "ssl"; //Secure conection
    $mail->Host = 'xxxx.com';
    $mail->Port = 00;
    $mail->Username = 'postmaster@xxx.xom';  // SMTP username
    $mail->Password = ''; // SMTP password
    $mail->From = 'postmaster@xxx.com';
    $mail->FromName = $senderName;
    $mail->AddReplyTo($senderEmail, $senderName); 
    $mail->AddAddress($receiverEmail, $receiverName);//send a copy to the client
    $mail->Subject = $mySubject;
    $mail->WordWrap = 80;
    $mail->AddEmbeddedImage('x.png', 'csvimg', 'csv.png'); // attach file logo.jpg, and later link to it using identfier logoimg
    //$mail->AddEmbeddedImage($serverRoot.'/images/'.$stationeryPrefix.'Header.jpg', $stationeryPrefix.'Header', $stationeryPrefix.'Header.jpg');
    //$mail->AddEmbeddedImage($serverRoot.'/images/'.$stationeryPrefix.'Footer.jpg', $stationeryPrefix.'Footer', $stationeryPrefix.'Footer.jpg');
    //$headerImage = $serverRoot.'/images/'.$stationeryPrefix.'Header.jpg';
    $mail->Body = $stationeryHeader;
    $mail->Body .= $myMessage;
    $mail->Body .= $stationeryFooter;
    if(!$mail->Send()){
        echo '<br />Message FAILED to '.$receiverEmail;
        '.$reportArray[1],$company,$defaultEmail);
    }else{
        echo '<br />Message successfully sent to '.$receiverEmail;
    }//end if mail>send
}//end function sendMyEmail


?>

因此,我已经找到了我问题的答案,如果有人在未来遇到并需要帮助,我会将其张贴在这里:

angular script.js

$scope.sendemail = function(info){
            var req = {
                method: 'GET',
                url: 'ReportManual/manualemail.php',
            };
            //Call the URL and handle succes or error callback  --> G.H.
            $http(req).then(function successCallback(response) {
                     alert('The Report has been sent.');
                    console.log(response);

            }, function errorCallback(response) {
                alert('Report has not been sent');
                 console.log(response);
            });

        }
HTML:

<div class="mainpage">
<div>
<div class="row" style="padding:10px">

    <p> Click on this button Reports:</p>
   <button  ng-click=????" 
                        class="btn btn-default">Send Report</button>
</div>      

</div>
</div>
$scope.getreportrta = function (key) {
    var req = {
        method: 'GET',
        url: '/XXXX/XXXX/php/cronHourly.php',
    };
    $http(req).then(function successCallback(response) {
        $scope.(*don't know how to fetch this*);
    }, function errorCallback(response) {

    });
}        
<div class="row" style="padding:10px">
  <p> Click on this button to send the Reports:</p>
   <button ng-click="sendemail()">SUBMIT</button>
</div>

单击此按钮发送报告:

提交
PHP:manualemail.PHP

function sendMyEmail($receiverName,$receiverEmail,$mySubject,$myMessage,$senderName,$senderEmail){
    //global $company,$companyPhone,$defaultEmail,$domain,$shopAddress,$stationeryPrefix,$siteStatus,$reportArray,$Host,$Port,$Username,$Password,$serverRoot;
$stationeryHeader = "<body bgcolor='#cccccc' leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'><style>
body {
      font-family: Arial;
       font-size: 12pt;
}
</style>
<br>
<table id='Table_01' border='0' cellpadding='0' align='center' bgcolor='#FFFFFF' width='800'>

<tr><td width='20'></td><td><br>";

$stationeryFooter = "</td><td width='20'></td></tr>

</table></body>";

    //$mail = new PHPMailer();
     $mail = new PHPMailer(true);

    $mail->IsHTML(true);
    $mail->isSMTP();  // tell the class to use SMTP
    $mail->SMTPAuth   = true; 
    //$mail->SMTPSecure  = "ssl"; //Secure conection
    $mail->Host = 'xxxx.com';
    $mail->Port = 00;
    $mail->Username = 'postmaster@xxx.xom';  // SMTP username
    $mail->Password = ''; // SMTP password
    $mail->From = 'postmaster@xxx.com';
    $mail->FromName = $senderName;
    $mail->AddReplyTo($senderEmail, $senderName); 
    $mail->AddAddress($receiverEmail, $receiverName);//send a copy to the client
    $mail->Subject = $mySubject;
    $mail->WordWrap = 80;
    $mail->AddEmbeddedImage('x.png', 'csvimg', 'csv.png'); // attach file logo.jpg, and later link to it using identfier logoimg
    //$mail->AddEmbeddedImage($serverRoot.'/images/'.$stationeryPrefix.'Header.jpg', $stationeryPrefix.'Header', $stationeryPrefix.'Header.jpg');
    //$mail->AddEmbeddedImage($serverRoot.'/images/'.$stationeryPrefix.'Footer.jpg', $stationeryPrefix.'Footer', $stationeryPrefix.'Footer.jpg');
    //$headerImage = $serverRoot.'/images/'.$stationeryPrefix.'Header.jpg';
    $mail->Body = $stationeryHeader;
    $mail->Body .= $myMessage;
    $mail->Body .= $stationeryFooter;
    if(!$mail->Send()){
        echo '<br />Message FAILED to '.$receiverEmail;
        '.$reportArray[1],$company,$defaultEmail);
    }else{
        echo '<br />Message successfully sent to '.$receiverEmail;
    }//end if mail>send
}//end function sendMyEmail


?>
function sendMyEmail($receiverName,$receiverEmail,$mySubject,$myMessage,$senderName,$senderEmail){
    //global $company,$companyPhone,$defaultEmail,$domain,$shopAddress,$stationeryPrefix,$siteStatus,$reportArray,$Host,$Port,$Username,$Password,$serverRoot;
$stationeryHeader = "<body bgcolor='#cccccc' leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'><style>
body {
      font-family: Arial;
       font-size: 12pt;
}
</style>
<br>
<table id='Table_01' border='0' cellpadding='0' align='center' bgcolor='#FFFFFF' width='800'>

<tr><td width='20'></td><td><br>";

$stationeryFooter = "</td><td width='20'></td></tr>

</table></body>";

    //$mail = new PHPMailer();
     $mail = new PHPMailer(true);

    $mail->IsHTML(true);
    $mail->isSMTP();  // tell the class to use SMTP
    $mail->SMTPAuth   = true; 
    //$mail->SMTPSecure  = "ssl"; //Secure conection
    $mail->Host = 'xxxx.com';
    $mail->Port = 00;
    $mail->Username = 'postmaster@xxx.xom';  // SMTP username
    $mail->Password = ''; // SMTP password
    $mail->From = 'postmaster@xxx.com';
    $mail->FromName = $senderName;
    $mail->AddReplyTo($senderEmail, $senderName); 
    $mail->AddAddress($receiverEmail, $receiverName);//send a copy to the client
    $mail->Subject = $mySubject;
    $mail->WordWrap = 80;
    $mail->AddEmbeddedImage('x.png', 'csvimg', 'csv.png'); // attach file logo.jpg, and later link to it using identfier logoimg
    //$mail->AddEmbeddedImage($serverRoot.'/images/'.$stationeryPrefix.'Header.jpg', $stationeryPrefix.'Header', $stationeryPrefix.'Header.jpg');
    //$mail->AddEmbeddedImage($serverRoot.'/images/'.$stationeryPrefix.'Footer.jpg', $stationeryPrefix.'Footer', $stationeryPrefix.'Footer.jpg');
    //$headerImage = $serverRoot.'/images/'.$stationeryPrefix.'Header.jpg';
    $mail->Body = $stationeryHeader;
    $mail->Body .= $myMessage;
    $mail->Body .= $stationeryFooter;
    if(!$mail->Send()){
        echo '<br />Message FAILED to '.$receiverEmail;
        '.$reportArray[1],$company,$defaultEmail);
    }else{
        echo '<br />Message successfully sent to '.$receiverEmail;
    }//end if mail>send
}//end function sendMyEmail


?>
函数sendmail($receiverName、$receiverEmail、$mySubject、$myMessage、$senderName、$senderEmail){
//全局$company、$companyPhone、$defaultEmail、$domain、$shopAddress、$stationeryPrefix、$siteStatus、$reportArray、$Host、$Port、$Username、$Password、$serverRoot;
$stationeryHeader=”
身体{
字体系列:Arial;
字号:12号;
}


“; $stationeryFooter=” "; //$mail=new PHPMailer(); $mail=新的PHPMailer(true); $mail->IsHTML(true); $mail->isSMTP();//告诉类使用SMTP $mail->SMTPAuth=true; //$mail->SMTPSecure=“ssl”;//安全连接 $mail->Host='xxxx.com'; $mail->Port=00; $mail->Username=postmaster@xxx.xom“;//SMTP用户名 $mail->Password='';//SMTP密码 $mail->Frompostmaster@xxx.com'; $mail->FromName=$senderName; $mail->AddReplyTo($senderEmail,$senderName); $mail->AddAddress($receiverEmail,$receiverName);//向客户端发送副本 $mail->Subject=$mySubject; $mail->WordWrap=80; $mail->AddEmbeddedImage('x.png','csvimg','csv.png');//附加文件logo.jpg,稍后使用标识符logoimg链接到该文件 //$mail->AddEmbeddedImage($serverRoot./images/'.$stationeryPrefix.Header.jpg',$stationeryPrefix.Header',$stationeryPrefix.Header.jpg'); //$mail->AddEmbeddedImage($serverRoot./images/'.$stationeryPrefix.Footer.jpg',$stationeryPrefix.Footer',$stationeryPrefix.Footer.jpg'); //$headerImage=$serverRoot./images/'.$stationeryPrefix.Header.jpg'; $mail->Body=$stationeryHeader; $mail->Body.=$myMessage; $mail->Body.=$stationeryFooter; 如果(!$mail->Send()){ 将“
消息回送到“$receiverEmail”失败; “.$reportArray[1],$company,$defaultEmail); }否则{ 回显“
消息已成功发送到“.$receiverEmail; }//如果邮件>发送,则结束 }//结束函数sendmail ?>
您将从php端得到错误,您可以看到引号错误。首先,我不知道如何在angular js中调用此php函数,我不知道该语法是否正确?您不需要
public\u html/XXXX/XXXX/php/cronHourly.php
调用php,在您的服务器中,您正在使用apache,并且您已将ip或域指向放置代码的特定文件夹,因此首先确保并找到您创建的php函数工作的url。出于调试目的,请在successCallback和errorCallback中放置
console.log(response)
。检查开发人员控制台的网络选项卡以查看XHR的响应。我感谢您的评论,但我想知道的是如何在成功回调中获得函数,而成功回调又可以在HTML中调用,我不确定语法,因此在进行这些更正之前,我无法进一步说明原因。