I need help with implementing Mailgun email service in my CodeIgniter application for sending account verification emails. Everything works fine on my local development environment using XAMPP, but when I upload to my production server, I’m getting errors.
The error I’m seeing is:
Fatal error: syntax error, unexpected ‘[’ in /home/public_html/project/mailgun/vendor/guzzlehttp/psr7/src/functions.php on line 78
I thought maybe the issue was with the vendor files being different between operating systems, so I reinstalled all the Mailgun dependencies directly on the server using composer, but the problem persists.
My local setup runs PHP 5.6.25 on Windows with XAMPP, while the production server uses PHP 5.3.3 on Linux CentOS. Could this PHP version difference be causing the issue?
Here’s my controller code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require '/home/public_html/myapp/mailgun/vendor/autoload.php';
use Mailgun\Mailgun;
class Signup extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Member_model');
$this->load->helper('cookie');
}
public function index($parameter = '')
{
if (($this->session->userdata('memberLogin') == TRUE))
{
redirect(site_url('members/home'));
}
if (isset($_POST['signup'])){
$formData['postdata'] = $_POST;
if(!empty($_POST['fname']) && !empty($_POST['lname']) &&
!empty($_POST['email']) && !empty($_POST['pwd']) &&
!empty($_POST['company']) && !empty($_POST['location']) &&
!empty($_POST['street'])){
$emailExists = $this->Member_model->verifyEmail();
if($emailExists==true){
$this->session->set_flashdata('error', '<p>This email address is already in use!</p>');
}else{
$userHandle = str_replace(' ', '',$_POST['fname'].$_POST['lname']);
$cleanHandle = preg_replace('/[^A-Za-z0-9\-]/', '', $userHandle);
$handleExists = $this->Member_model->verifyHandle($cleanHandle);
if($handleExists==true){
$finalHandle = $this->generateHandle($cleanHandle);
}else{
$finalHandle = $cleanHandle;
}
$formData['token'] = rand(10000,999999);
$formData['name'] = $_POST['fname'];
$this->Member_model->createMember($finalHandle,$formData['token']);
mkdir("/home/public_html/members/".$finalHandle);
$emailSubject = "Account Verification";
$emailContent = $this->load->view('emails/signup.php',$formData,TRUE);
# Initialize Mailgun client
$mailgunClient = new Mailgun('my_api_key_here');
$mailgunDomain = "my_domain_here";
# Send email via Mailgun API
$response = $mailgunClient->sendMessage($mailgunDomain, array(
'from' => 'Support <[email protected]>',
'to' => 'Member <[email protected]>',
'subject' => 'Welcome to our platform',
'text' => 'Please verify your account'
));
$this->session->set_flashdata('success','Registration successful!');
redirect(site_url('signup/success'));
}
}else{
$this->session->set_flashdata('error', '<p>Please fill all required fields!</p>');
}
}
$formData['title']='';
$formData['parameter']=$parameter;
$this->load->view('signup/form',$formData);
}
function generateHandle($baseString) {
$finalHandle = $baseString;
for ($counter = 1; $counter < 50; $counter++) {
$handleCheck = $this->Member_model->verifyHandle($baseString.$counter);
if(empty($handleCheck)){
$finalHandle = $baseString.$counter;
break;
}
}
return $finalHandle;
}
}
?>
Any ideas what might be causing this syntax error? I’m really stuck on this one.