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 maccms影视模板 制作影视网站失败 求
  • ¥15 stm32按键设置闹钟数进退位不正常
  • ¥15 三电平逆变器中点电位平衡问题
  • ¥20 这怎么写啊 java课设
  • ¥15 用C语言完成一个复杂的游戏
  • ¥15 如何批量更改很多个文件夹里的文件名中包含文件夹名?
  • ¥50 MTK手机模拟HID鼠标出现卡顿
  • ¥20 求下下面这个数据结构代码
  • ¥20 前端 二进制文件流图片转化异常
  • ¥15 github上的这个C语言项目如何跑起来