我正试图通过Elastix上的php发送电子邮件。当我将php作为ssh运行时,它可以工作,但当我尝试在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有什么帮助吗?
所以,我终于可以通过PHP发送电子邮件了。PHPMailer库在PHP5.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;
// });
//}
}