dongpi2503 2014-10-21 20:49
浏览 30
已采纳

PHP-EWS while循环错误无法重新声明类EwsSendEmail

I am trying to pull out emails from a SQL database and then send an email to each of those emails using EWS via PHP. But when I put the PHP-EWS code https://github.com/jamesiarmes/php-ews/ inside of a while loop it gives me the error "Cannot redeclare class EwsSendEmail".

Here the layout of the code, it would look like I cannot have the class inside the while loop. But not sure how else I can get all the data from the SQL table and send a unique email for each and I am not very familiar with the use of a class. The code works fine if I only pull one record from the SQL by adding TOP 1 after SELECT. I do appreciate any help.

<?php
$sql = "SELECT FIELDNAME FROM TABLE";
$stmt = sqlsrv_query( $conn, $sql);
if ($stmt === false ) {
die (print_r( sqlsrv_errors(), true));
}
while ( $column = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_BOTH)) {
// Do some data processing here
require_once($ewspath.'EWSType/IncludetheEWSFilesHere.php');
class EwsSendEmail
{
    protected function sendEmail()
    {
        $server = 'myserver';
        $username = 'myuser';
        $password = 'mypass';
        $ews = new ExchangeWebServices($server, $username, $password);

        // Process the EWS Code Here

        $response = $ews->CreateItem($message);
        //var_dump($response);
    }

    function __construct()
    {
        $this->sendEmail();
    }
}
$page = new EwsSendEmail();
}

?>
  • 写回答

1条回答 默认 最新

  • duanjiong5686 2014-11-20 14:57
    关注

    So I worked around this issue by removing the class and function and just including the php code in the while loop. Maybe not the best practice solution but it works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 c语言,请帮蒟蒻看一个题
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)