2017-05-13 1 views
-1

私はOpencart V2.0.1.1を1つのプロジェクトに使用しており、製品ページ(.tpl)にカスタムフォームがあります。私はそのフォームの提出時に店主にメールを送りたいと思っています。私はそれを処理し、モデルまでのデータを受け取ることができますが、モデルから私はメールを送信することができず、私はエラー以下になっています。カートを開く

SyntaxError: Unexpected token < OK Notice: Undefined property: Mail::$ErrorInfo in /opt/lampp/htdocs/dutees/catalog/model/catalog/product.php on line 784{"success":"success"}

以下は私のコード

// CONTROLLER FUNCTION 

public function getquote() 
{ 
    $data = array(); $json = array(); 

    if (isset($this->request->post['name'])) { 
     $data['name'] = $this->request->post['name']; 
    } 
    if (isset($this->request->post['email'])) { 
     $data['email'] = $this->request->post['email']; 
    } 
    if (isset($this->request->post['mobile'])) { 
     $data['mobile'] = $this->request->post['mobile']; 
    } 
    if (isset($this->request->post['address'])) { 
     $data['address'] = $this->request->post['address']; 
    } 
    if (isset($this->request->post['description'])) { 
     $data['description'] = $this->request->post['description']; 
    } 
    if($this->config->get('config_email') != 'null' || $this->config->get('config_email') !='') 
     $data['store_email'] = $this->config->get('config_email'); 

    if($this->config->get('config_name') != 'null' || $this->config->get('config_name') !='') 
     $data['store_name'] = $this->config->get('config_name'); 

    $this->load->model('catalog/product'); 
    $gq_status = $this->model_catalog_product->sendQuote($data); 

    if($gq_status = "success"){ 
     $json['success'] = "success"; 
    }else{ 
     $json['error'] = "Error : We are unable to send your request now, please use contact-us form"; 
    } 
    $this->response->addHeader('Content-Type: application/json'); 
    $this->response->setOutput(json_encode($json)); 

} 


// MODEL FUNTION 

public function sendQuote($data = array()) { 

    $status = ""; $name ="";$email ="";$mobile ="";$address ="";$description =""; 

    if(isset($data['name'])) 
     $name = $data['name']; 
    else 
     $name = "Not Available"; 

    if(isset($data['email'])) 
     $email = $data['email']; 
    else 
     $email = "Not Available"; 

    if(isset($data['mobile'])) 
     $mobile = $data['mobile']; 
    else 
     $mobile = "Not Available"; 

    if(isset($data['address'])) 
     $address = $data['address']; 
    else 
     $address = "Not Available"; 

    if(isset($data['description'])) 
     $description = $data['description']; 
    else 
     $description = "Not Available"; 


    if(isset($data['store_email'])) 
     $store_email = $data['store_email']; 
    else 
     $store_email = "[email protected]"; 

    if(isset($data['store_name'])) 
     $store_name = $data['store_name']; 
    else 
     $store_name = "Enquiry"; 

    $message = ' 
      <html> 
      <body> 
       <MY HTML MAIL CONTENT GOES HERE> 
      </body> 
      </html> 
     '; 

    $this->load->mail; 

    $mail = new Mail(); 

    $mail->protocol = $this->config->get('config_mail_protocol'); 
    $mail->parameter = $this->config->get('config_mail_parameter'); 
    $mail->hostname = $this->config->get('config_smtp_host'); 
    $mail->username = $this->config->get('config_smtp_username'); 
    $mail->password = $this->config->get('config_smtp_password'); 
    $mail->port = $this->config->get('config_smtp_port'); 
    $mail->timeout = $this->config->get('config_smtp_timeout');    
    $mail->setTo($store_email); 
    $mail->setFrom($email); 
    $mail->setSender($store_name); 
    $mail->setSubject("Product Get Quote"); 
    //$mail->setText("test message body text"); 
    $mail->setHtml($message); 
    if(!$mail->send()) { 
     $status = 'Mailer Error: ' . $mail->ErrorInfo; 
    } else { 
     $status = 'success'; 
    } 

    return $status; 


} 

// VIEW AJAX 

<script> 
$('#gq-submit').click(function(){ 
    var name=$('#gq-name').val(); 
    var email=$('#gq-email').val(); 
    var mobile=$('#gq-mobile').val(); 
    var address=$('#gq-address').val(); 
    var description=$('#gq-description').val(); 
    if(name != '' && email != ''&& mobile != '' && description != ''){ 
    $.ajax({ 
     type:'post', 
     url:'index.php?route=product/product/getquote', 
     dataType: 'json', 
     data:'name='+name+'&email='+email+'&mobile='+mobile+'&address='+address+'&description='+description, 
    beforeSend: function() { 
     $('#gq-submit').button('loading'); 
    }, 
    complete: function() { 
     $('#gq-submit').button('reset'); 
    }, 
    success: function(json) { 
     $('.alert-success, .alert-danger').remove(); 
     $('.form-group').removeClass('has-error'); 

     if (json['error']) { 
      $('#gq-showcheck').after('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + '</div>'); 
     } 

     if (json['success']) { 
     $('#gq-showcheck').after('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>'); 
     } 
    }, 
    error: function(xhr, ajaxOptions, thrownError) { 
     console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); 
    } 
    });}else{ 
     $('#gq-showcheck').after('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + "Please fill all the fields" + '</div>'); 

    } 
}); 
</script> 

答えて

1

あなたがメールを送信することができないで、多分、メールの設定が間違っていると Opencart自身のメールクラスは、その中にいないのErrorInfoフィールドがあります。 参照:system/library/mail.php まず、正しいメールパラメータを設定し、$ mail-> ErrorInfoは存在しないので使用しないでください。メールの送信中にエラーが発生すると、trigger_errorが呼び出されます。

+0

Thx Istvan ..私はErrorInfoを取り出して$ this-> load-> mailも削除しました。それは今働いています。 –

関連する問題