Search code examples
phpemailphpmailerelastix

I can't send email via php on Elastix


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 [email protected] -t [email protected] -u Subject -m Message-s example.com.mx -o tls=yes -xu [email protected] -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 = '[email protected]';      
    $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 = '[email protected]';
    $mail->FromName = 'Name';
    $mail->addAddress('[email protected]'); 

    $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?


Solution

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