2012-05-01 5 views
0

이메일을 통해 수신자에게 연락 양식을 보낼 때 CakePHP에서 이상한 오류가 발생했습니다. 연락처 양식이 작성되고 제출되면, CakePHP는 수신자에게 전자 메일을 발송합니다. 그러나 한 번 이메일을 보내는 대신 한 번에 두 개의 이메일을 보내는 것처럼 보입니다.CakePHP 2가 매번 2 개의 이메일을 보냅니다.

내 컨트롤러 코드는 이것이다 :

var $helpers = array('Html', 'Form', 'Js'); 
var $components = array('Email', 'Session'); 

public function index() { 
    $this->layout = 'modal'; 

    if(isset($this->data['Contact'])) { 
     $userName = $this->data['Contact']['yourname']; 
     $userPhone = $this->data['Contact']['yourtelephone']; 
     $userEmail = $this->data['Contact']['youremail']; 
     $userMessage = $this->data['Contact']['yourquestion']; 

     $email = new CakeEmail(); 
     $email->viewVars(array(
       'userName' => $userName, 
       'userPhone' => $userPhone, 
       'userEmail' => $userEmail, 
       'userMessage' => $userMessage 
     )); 
     $email->subject(''.$userName.' has asked a question from the website'); 
     $email->template('expert', 'standard') 
      ->emailFormat('html') 
      ->to('[email protected]') 
      ->from('[email protected]', 'The Postman') 
      ->send(); 

     if ($email->send($userMessage)) { 
      $this->Session->setFlash('Thank you for contacting us'); 
     } 
     else { 
      $this->Session->setFlash('Mail Not Sent'); 
     } 

    } 
} 

을 그리고 이것은 문의 양식에 대한 코드입니다 :

 <?php 
      echo $this->Form->create('Contact', array('url' => '/contact/ask-the-expert/', 'class' => 'contact')); 

      echo $this->Form->input('yourname', array(
       'type' => 'text', 
       'label' => 'Your Name <span class="star">*</span>', 
      )); 
      echo $this->Form->input('yourtelephone', array(
       'type' => 'text', 
       'label' => 'Your Telephone', 
      )); 
      echo $this->Form->input('youremail', array(
       'type' => 'text', 
       'label' => 'Your Email <span class="star">*</span>', 
      )); 
      echo $this->Form->input('yourquestionAnd ', array(
       'type' => 'textarea', 
       'label' => 'Your Question <span class="star">*</span>', 
      )); 
      echo $this->Form->submit(); 

      echo $this->Form->end(); 
     ?> 

건배!

+0

어떤 웹 서버를 사용하고 있습니까? – debianek

+0

프로젝트가 XAMPP 설정에서 로컬로 호스팅됩니다. – mickburkejnr

답변

1

메일 보내기 if ($this->request->is('post')) {} 안에 코드를 보내고 시도하십시오.

업데이트
코드를 업데이트했습니다.

var $helpers = array('Html', 'Form', 'Js'); 
var $components = array('Email', 'Session'); 

public function index() { 
$this->layout = 'modal'; 

if(isset($this->data['Contact'])) { 
    $userName = $this->data['Contact']['yourname']; 
    $userPhone = $this->data['Contact']['yourtelephone']; 
    $userEmail = $this->data['Contact']['youremail']; 
    $userMessage = $this->data['Contact']['yourquestion']; 

    $email = new CakeEmail(); 
    $email->viewVars(array(
      'userName' => $userName, 
      'userPhone' => $userPhone, 
      'userEmail' => $userEmail, 
      'userMessage' => $userMessage 
    )); 
    $email->subject(''.$userName.' has asked a question from the website'); 
    $email->template('expert', 'standard') 
     ->emailFormat('html') 
     ->to('[email protected]') 
     ->from('[email protected]', 'The Postman') 


    if ($email->send($userMessage)) { 
     $this->Session->setFlash('Thank you for contacting us'); 
    } 
    else { 
     $this->Session->setFlash('Mail Not Sent'); 
    } 

    } 
} 
+0

두 개의 전자 메일을 여전히 배달합니다. – mickburkejnr

+0

@mickburkejnr이 코드를 업데이트하여'Send()'함수를 삭제했습니다. – Saanch

+0

그것은 고쳐졌지만'if ($ this-> request-> is ('post')) {}'를 사용할 필요가 없었습니다. – mickburkejnr

관련 문제