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

时间:2015-11-09 16:17:53

标签: php email phpmailer elastix

我正在尝试通过php在Elastix上发送电子邮件。 当我作为ssh运行php时它可以工作但是当我尝试在Web(PHP)上执行它时我不发送任何东西。 这是我的代码:

#!/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");
?>

我认为是关于权限的东西,因为当我在命令行上运行它时输出是:

  

并发送电子邮件。但是当我尝试通过Web打开文件时,我没有发送任何内容,输出是下一个:

  

Asteriks

所以我试图给Asteriks root权限,但它不起作用:(。 在另一个尝试这样做我下载PHPMailer库但我不发送电子邮件。我尝试在带有Xampp的Windows上执行此操作,并且它的工作原理与PHP(5.1.6)的版本相同。

这是我的PHPMailer代码:

<?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';
    }
?>

它适用于Windows,但它不适用于Elastix 有帮助吗?

1 个答案:

答案 0 :(得分:0)

所以,最后我能够通过PHP发送电子邮件。 PHPMailer库在PHP 5.1.6上无法正常运行 因为(最终)给我的错误是:

,所以我抓住了一些机会
  

解析错误:语法错误,意外的T_FUNCTION   第3040行的var / www / html /[...]/ class.phpmailer.php

所以我把class.phpmailer.php的代码传给了这个:

/**
     * 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;
        //        });
        //}
    }