0

我试图使用 joomla 邮件发送电子邮件,但它确实有效,有什么建议吗?我错过了什么?我在网上搜索过,但没有帮助。

我得到的唯一错误是500,我不明白为什么......

这是实际的代码:

<?php
//framework joomla
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR ); 
define( 'JPATH_BASE', realpath(dirname(__FILE__) . "/../"));
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
$mainframe =& JFactory::getApplication('site');

//get vars
$session =& JFactory::getSession();
$num1 = $session->get('variable1');  
$num2 = $session->get('variable2');  
$val= $session->get('variable3');  
$uq= $session->get('unique');
$sendto= $session->get('mail');

//mail
$mailer =& JFactory::getMailer();
$mailer->setSender('some1@domain.com');
$recipient = array($sendto, 'some1else@domain.com');
$mailer->addRecipient($recipient);


$body   = '<h2>sometext</h2>'
    . '<div>sometext</div>'
    . '<div> blabla' echo $num1 'blabla </div>'
    . '<div> texttext' echo $num2 'texet </div>'
    . '<div> texttext' echo $val 'text </div>';

$mailer->isHTML(true);
$mailer->Encoding = 'base64';
$mailer->setBody($body);
$mailer->AddEmbeddedImage("$uq".".gif", "image_0", "", "base64", "image/gif");
$mailer->addAttachment("$uq".".gif");  

//send 
$send =& $mailer->Send();
if ( $send !== true ) {
    //Elimina .gif 
    $mask = "*.gif";
    array_map( "unlink", glob( $mask ) );
    unset($mailer); 
    echo 'error: ' . $send->message;
} else {
unset($mailer);
    //Elimina .gif 
    $mask = "*.gif";
    array_map( "unlink", glob( $mask ) );
    echo 'done';
}
?>

忘记添加有关平台的规格:

PHP 版本 5.3.22

Joomla!版本 2.5.9

如果您需要任何其他信息,请询问。

更新:我尝试了另一个 joomla!版本,代码的简化版本,没有变量,只有一封电子邮件,纯文本电子邮件......似乎没有任何工作。带有空白错误日志的内部服务器错误(500)...(奇怪,但安装它位于具有许多其他安装的子目录中,并且我的虚拟主机允许我只看到“根”日志,所以我认为这是问题所在的空白错误日志...)

4

3 回答 3

0

ok, solved!

this might help someone else so, here is how:

$config =& JFactory::getConfig();

this line grabs the email configuration of Joomla, without this Jmail will not send emails.

//body email
$body   .= "<h2>Texttext</h2>" . "\n";
$body   .= "<div>TexttextTexttextTexttext" . $blockh .  " Texttext " . $blockd . "\n";
$body   .= "<div> TexttextTexttext <span> " .  $num1 . " </span> Texttext </div>" . "\n";
$body   .= "<div>TexttextTexttextTexttext <span> " .  $val . " </span> Texttext </div>";

previus concatenation of the body was not working, it seems that double quotes are needed to work...

$mailer->isHTML();

the "true" inside is not necessary since true is the default value..

于 2013-05-02T08:08:41.557 回答
0

不太确定这是否是您问题的根源。但是 $mail->setSender() 接受一个数组。示例: $mail->setSender(array('SENDER EMAIL', 'SENDER NAME'));

$mail->addRecipient() 接受字符串或数组。如果您将电子邮件发送给多个收件人,请使用数组;如果您仅将电子邮件发送给 1 个收件人,请使用字符串。

希望这可以帮助

于 2013-04-25T11:11:14.253 回答
0

回答 KentaS 的评论

以前的身体连接不起作用,似乎需要双引号才能工作......

它与单引号或双引号无关。在您的原始帖子中,您有:

$body   = '<h2>sometext</h2>'
. '<div>sometext</div>'
. '<div> blabla' echo $num1 'blabla </div>'
. '<div> texttext' echo $num2 'texet </div>'
. '<div> texttext' echo $val 'text </div>';

那个部分:

'<div> blabla' echo $num1 'blabla </div>'

导致语法错误(字符串,后跟,没有串联,调用“echo”,后跟,没有串联,一个字符串......!

与单引号一起使用的东西:

$body   = '<h2>sometext</h2>'
. '<div>sometext</div>'
. '<div> blabla' . $num1 . 'blabla </div>'
. '<div> texttext' . $num2 . 'texet </div>'
. '<div> texttext' . $val . 'text </div>';

使用双引号,您可以做得更短:

$body   = "<h2>sometext</h2>"
. "<div>sometext</div>"
. "<div> blabla $num1 blabla </div>"
. "<div> texttext $num2 texet </div>"
. "<div> texttext $val text </div>";

干杯,
多姆

于 2013-09-05T19:42:58.813 回答