2013-05-21 19 views
0

我的代碼在格式爲html時有效。JMail用於雜湊組件編程

<pre> 

public function partOrder() 
{  
     $input=JFactory::getApplication()->input; 
    $mailer =JFactory::getMailer(); 
    $config =JFactory::getConfig(); 
    $mailer->setSender(array("[email protected]","name")); 
    $mailer->addRecipient("[email protected]"); 

    $body="Some html message"; 

    $mailer->isHTML(true); 
     $mailer->Encoding = 'base64'; 
    $mailer->setBody($body); 
    $send =$mailer->Send(); 
    $respond=""; 
    if ($send !== true) { 
    $respond= 'Error sending email: ' . $send->message; 
    } else { 
     $respond= 'Mail sent'; 
    } 

    echo $respond; 

} 

</pre> 

當我在控制器上對json格式使用相同的函數時,我得到「郵件發送」消息。但郵件沒有達到收件人;

回答

1

我不認爲你的功能有什麼問題。

然而,我注意到,Gmail是相當挑剔的,當談到哪些電子郵件來波谷與收件箱:

  1. 所有全局配置 - >服務器>郵件設置必須填寫有效。
  2. 這些設置都將用於JMail的配置

// Initialize some variables 
$app   = JFactory::getApplication(); 
$mailer   = JFactory::getMailer(); 

// Get mailer configuration 
$mailfrom  = $app->getCfg('mailfrom'); 
$fromname  = $app->getCfg('fromname'); 
$sitename  = $app->getCfg('sitename'); 

// Clean the email data 
$contact_to  = JMailHelper::cleanAddress($data['contact_to']); 
$subject  = JMailHelper::cleanSubject($data['contact_subject']); 
$body   = JMailHelper::cleanBody( $data['contact_message']); 
$reply_to_email = JMailHelper::cleanAddress($data['contact_reply_to']); 
$reply_to_name = JMailHelper::cleanLine( $data['contact_reply_to_name']); 

// Construct mailer 
$mailer 
    ->addRecipient($contact_to) 
    ->addReplyTo(array($reply_to_email, $reply_to_name)) 
    ->setSender(array($mailfrom, $fromname)) 
    ->setSubject($sitename . ': ' . $subject) 
    ->setBody($body) 
; 

// Send email 
$sent   = $mailer->Send(); 
+0

但我的代碼適用於html格式的,我嘗試過其他電子郵件收件人。他們都工作。但是,無論何時我將具有相同設置的json格式的此功能複製並粘貼到controllername.json.php文件中,電子郵件都不會到達收件人。我成功地收到了「發送郵件」消息。我認爲格式爲json時,某些內容不起作用。 – UfkaYolcu

+0

我有個主意。由於您使用的是json控制器,因此我認爲它正在通過ajax執行。也許你沒有正確填充電子郵件字段(即電子郵件發送到'[email protected]')?嘗試輸出輸入並與真實輸入進行比較。 –