2017-03-08 45 views
1

我试图使用mailgun api从我的网站发送用户注册确认电子邮件。我的网站位于共享主机上。当我在本地主机(WAMP服务器)上测试它时,mailgun api似乎完美地工作。当我尝试在源代码中使用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

由于这是一个语法错误,我下载并安装了mailgun依赖关系(即作曲家,狂饮适配器等)分别在Linux服务器上,因为本来我从我的本地复制的文件(Windows)和是根据 的印象,这些文件是不同的Windows和Linux。但是这也没有任何区别。

在localhost(WAMP)上运行php 5.6.25,在共享主机(CentOS)上运行php 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

问题正在更新PHP到30年6月5日的版本后问题。经过与Godaddy的客户支持长时间的交谈之后,他们建议我更新我的PHP。它完美后工作。