doucheng5705 2015-11-09 16:17
浏览 75
已采纳

我无法在Elastix上通过php发送电子邮件

I'm trying to send emails via php with on Elastix. When I run the php as a ssh it works but when I try to do it on Web (PHP) I doesn't send anything. This is my code:

#!/usr/bin/php -q  
<?php
    echo shell_exec('whoami');
    shell_exec("sudo sendEmail -f j.example@example.com -t example@example.com -u Subject -m Message-s example.com.mx -o tls=yes -xu j.user@example.com.mx -xp password");
?>

I think is something about permissions because when I run it on my command line the output is:

root

and the email is send. But in when I try to open the file via Web i doesn't send anything, The output is next:

Asteriks

So I tried to give Asteriks root permissions, but it doesn't work :(. In another try to do it I download the PHPMailer library but i doesn't send the email. I try to do it on Windows with Xampp and it works and is the same version of PHP (5.1.6).

This is my PHPMailer code:

<?PHP
    $mail = new PHPMailer;

    $mail->isSMTP();                                   
    $mail->Host = 'example.com';
    $mail->SMTPAuth = true;           
    $mail->Username = 'example@example.com';      
    $mail->Password = 'password';              
    $mail->SMTPSecure = 'ssl';             
    $mail->Port = 465;
    $mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
        )
    );

    $mail->From = 'example@example.com';
    $mail->FromName = 'Name';
    $mail->addAddress('example@example.com'); 

    $mail->WordWrap = 50;                                
    $mail->isHTML(true); 

    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    if(!$mail->send()) {

        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';
    }
?>

It works on Windows but it doesn't on Elastix Any help?

  • 写回答

1条回答 默认 最新

  • dpeqsfx5186 2015-11-09 16:27
    关注

    So, finally I was able to send emails via PHP. The PHPMailer Library didn't work properly on PHP 5.1.6 So I make a few chances on it since the error that (finally) gave me was:

    Parse error: syntax error, unexpected T_FUNCTION in var/www/html/[...]/class.phpmailer.php on line 3040

    So I chanced the code of class.phpmailer.php to this:

    /**
         * Clear queued addresses of given kind.
         * @access protected
         * @param string $kind 'to', 'cc', or 'bcc'
         * @return void
         */
        protected function clearQueuedAddresses($kind)
        {
            //if (version_compare(PHP_VERSION, '5.3.0', '<')) {
                $RecipientsQueue = $this->RecipientsQueue;
                foreach ($RecipientsQueue as $address => $params) {
                    if ($params[0] == $kind) {
                        unset($this->RecipientsQueue[$address]);
                    }
                }
            //} else {
            //    $this->RecipientsQueue = array_filter(
            //        $this->RecipientsQueue,
            //        function ($params) use ($kind) {
            //            return $params[0] != $kind;
            //        });
            //}
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看