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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。