2017-03-08 5 views
1

mailgun APIを使用して、自分のWebサイトからユーザー登録確認メールを送信しようとしています。私のサイトは共有ホストにあります。私がlocalhost(WAMPサーバー)でテストすると、mailgun APIが完全に動作するようです。ソースコード、つまりコントローラの中でapiを使用しようとすると、構文エラーが発生します。共有ホストは、Linuxベースの(CentOS)サーバーです。codeigniterでmailgun APIを使用する

これはエラーメッセージです。

Parse error: syntax error, unexpected '[' in /var/www/html/log2pdf/mailgun/vendor/guzzlehttp/psr7/src/functions.php on line 78

それは構文エラーだったので、私はもともと私はlocalhost(Windowsの場合)からファイルをコピーしていたので、私は、別にLinuxサーバ上mailgunの依存関係(すなわち作曲、がつがつ食うアダプタなど)をダウンロードしてインストールし、これらのファイルがWindowsとLinuxで異なることが印象されたのは でした。しかし、それでも違いはありませんでした。

ローカルホスト(WAMP)でphp 5.6.25、共有ホスト(CentOS)でph 5.3.3を実行しています。すべてのmailgun依存関係は、mailgunウェブページのコマンドを使用してインストールされました。

私はできることをすべて試しましたが、これについての助けには大変感謝します。

これは私のコントローラです:

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 
require '/var/www/html/mysite/mailgun/vendor/autoload.php'; 
use Mailgun\Mailgun; 

class Register extends CI_Controller { 

public function __construct() 
{ 
    parent::__construct(); 
    $this->load->model('User_model'); 
    $this->load->helper('cookie'); 
} 
public function index($param = '') 
{ 

    if (($this->session->userdata('userLogin') == TRUE)) 
    { 
     redirect(site_url('users/dashboard')); } 

    if (isset($_POST['registration'])){ 

     $data['postdata'] = $_POST; 

     if(!empty($_POST['firstname']) && !empty($_POST['lastname']) && 
     !empty($_POST['email']) && !empty($_POST['password']) && 
     !empty($_POST['organization']) && !empty($_POST['country']) && 
     !empty($_POST['address'])){ 

      $checkEmail = $this->User_model->checkEmail(); 

      if($checkEmail==true){ 

       $this->session->set_flashdata('error', '<p><font> 
     This Email id is already registered!</font></p>'); 

      }else{ 

       $un = str_replace(' ', '',$_POST['firstname'].$_POST['lastname']); 
       //remove all spaces 
       $unwsc = preg_replace('/[^A-Za-z0-9\-]/', '', $un); 
       // Removes special chars. 

       $checkusername = $this->User_model->checkusername($unwsc); 

       if($checkusername==true){ 

        $username = $this->getUserName($unwsc); 

       }else{ 
        $username = $unwsc; 
       } 

       $data['code'] = rand(0,100000); 
       $data['username'] = $_POST['firstname']; 

       $this->User_model->saveUser($username,$data['code']); 

       mkdir("/var/www/html/users/".$username); 

       /* 
       $fromemail="_my_organisation's_email_"; 
       $subject = "Registration Confirmation"; 

       //this was the email sender that i used initially 
          //it's codeigniter's built in email library. but after a 
         //while, emails stopped being delivered. 

       $this->load->library('email'); 
       $config['mailtype'] = 'html'; 
       $this->email->initialize($config); 
       $this->email->to($_POST['email']); 
       $this->email->from($fromemail, "_my_organisation's_email_"); 
       $this->email->subject($subject);      
       $body = $this->load->view('email/register.php',$data,TRUE); 
       $this->email->message($body);     
       $this->email->send(); 
       */          

       $subject = "Registration Confirmation"; 
       $body = $this->load->view('email/register.php',$data,TRUE); 

       //using mailgun api         

       # Instantiate the client. 
       $mgClient = new Mailgun('_my_mailgun_key_'); 
       $domain = "_my_maigun_domain_"; 

       # Make the call to the client. 
       $result = $mgClient->sendMessage($domain, array(
       'from' => 'NO REPLY <_my_organisation's_email_>', 
       'to'  => 'new user <_authorized_recipient_>', 
       'subject' => 'Mailgun test', 
       'text' => 'testing email sender' 
       )); 


       $this->session->set_flashdata('success','<p><font>Thanksfor registration!     </font></p>'); 
       redirect(site_url('register/complete'));  
      } 

     }else{ 
      $this->session->set_flashdata('error', '<p><font> 
      Missing Some Fields!</font></p>'); 
     } 
    } 
    $data['title']=''; 
    $data['param']=$param; 
    $this->load->view('registration/index',$data); 
} 
function getUserName($string) { 
    $result = $string; 
    for ($i = 1; $i < 100; $i++) { 
     $userChecking = $this->User_model->checkusername($string.$i); 
     if(empty($userChecking)){ 
      $result = $string.$i; 
      break; 
     } 
    } 
    return $result; 
} 
} 
?> 
+1

'' NO REPLY <_my_organisation's_email _> ''の代わりに' 'NO REPLY <_my_organisation \' s_email _> ''を試してみてください。ここでエスケープしているようです。 – Kaddath

+0

これはエスケープシーケンスではありません。 _my_organisation \ 's_email_は、私が使用した実際の電子メールIDの代わりのコメントです。 –

+0

このエラーは、実際のパッケージにあるようです。あなたは作曲家を使っていますか?もしそうなら、ライブラリの最新バージョンを使用していますか? –

答えて

3

問題はバージョン5.6.30にPHPを更新した後に解決しました。 Godaddyのカスタマーサポートとの長い話の後、彼らは私のPHPを更新するよう提案しました。それは完全に後に働いた。

関連する問題