7

基于Joomla!文档@ http://docs.joomla.org/Sending_email_from_extensions,我正在尝试使用以下代码发送电子邮件:

function sendmail($file,$mailto)
{  
    $mailer =& JFactory::getMailer();
    //var_dump($mailer); exit;
    $config =&JFactory::getConfig();
    $sender = array( 
        $config->getValue( 'config.mailfrom' ),
        $config->getValue( 'config.fromname' )
    );

    $mailer->setSender($sender);         

    $recipient = array($mailto);           
    $mailer->addRecipient($recipient);

    $body   = "Your body string\nin double quotes if you want to parse the \nnewlines etc";
    $mailer->setSubject('Your subject string');
    $mailer->setBody($body);
    // Optional file attached

    $mailer->addAttachment(JPATH_BASE.DS.'CSV'.DS.$file);

    $send =&$mailer->Send();

    if ( $send !== true ) {
        echo 'Error sending email: ' . $send->message;
    } else {
        echo 'Mail sent';
    }
}

$file是文件 zip 的完整路径,$mailto是我的 gmail。)

但是,当我发送邮件时,我收到错误:

无法实例化邮件功能。
致命错误:无法访问第 142 行 /var/www/html/dai/components/com_servicemanager/views/i0602/view.html.php 中的受保护属性 JException::$message

是什么导致了这个错误?

4

4 回答 4

2

请保持理智,不要尝试使用 Joomla 的邮件程序实现。正如您所经历的那样,它不仅不可靠,而且对不同的字符集和 HTML 内容的处理能力也很差。只需包含并使用PHPMailer

于 2012-10-03T13:04:39.097 回答
1

改变

echo 'Error sending email: ' . $send->message;

echo 'Error sending email:'.$send->get('message');

然后再次运行您的代码。您得到的错误应该告诉我们为什么它没有实例化。

于 2013-03-07T05:12:54.907 回答
1

在 joomla 中发送带有附件文件的邮件

   $from="noreplay@gmail.com";//Please set Proper email id
   $fromname="noreplay";
   $to ='admin@gmail.com';
   // Set a you want send email to
   $subject = "Download";
   $message = "Thank you For Downloading";
   $attachment = JPATH_BASE.'/media/demo.pdf';
   // set a file path
   $res = JFactory::getMailer()->sendMail($from, $fromname, $to,$subject,     $message,$mode=1,$cc = null, $bcc = null, $attachment);
   if($res)
   {
        $errormsg = "Mail Successfully Send";
   }
   else
   {
     $errormsg ="Mail Not Send";
   }

检查收件箱或垃圾邮件文件夹中的邮件后。
垃圾邮件文件夹中的邮件,因为从 id 中未正确设置电子邮件 ID。

于 2014-03-13T09:48:18.427 回答
0

经过几年的 Joomla 开发,我推荐使用RSJOOMLA 的 RSFORM PRO在您网站的访问者填写表格后为您发送邮件。它比处理内部邮件服务器要容易得多。

于 2012-10-02T13:26:16.657 回答