I’m having trouble integrating Mailgun email service into my CodeIgniter project for sending account verification emails. Everything works fine on my local development environment (XAMPP on Windows), but when I upload to my production server, I get 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 cross-platform compatibility, so I reinstalled all the Mailgun dependencies directly on the Linux server using composer, but the problem persists.
My local setup runs PHP 5.6.25 while the production server runs PHP 5.3.3 on CentOS. I followed the official Mailgun installation guide for setting up dependencies.
Here’s my controller code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require '/home/public_html/myproject/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 process($token = '')
{
if (($this->session->userdata('memberLogin') == TRUE))
{
redirect(site_url('members/home'));
}
if (isset($_POST['signup'])){
$formData['postdata'] = $_POST;
if(!empty($_POST['name']) && !empty($_POST['surname']) &&
!empty($_POST['email']) && !empty($_POST['pwd']) &&
!empty($_POST['company']) && !empty($_POST['location'])){
$emailExists = $this->Member_model->verifyEmail();
if($emailExists==true){
$this->session->set_flashdata('error', '<p>This email address is already in use!</p>');
}else{
$handle = str_replace(' ', '',$_POST['name'].$_POST['surname']);
$cleanHandle = preg_replace('/[^A-Za-z0-9\-]/', '', $handle);
$handleExists = $this->Member_model->verifyHandle($cleanHandle);
if($handleExists==true){
$finalHandle = $this->generateHandle($cleanHandle);
}else{
$finalHandle = $cleanHandle;
}
$formData['activationCode'] = rand(10000,999999);
$formData['memberName'] = $_POST['name'];
$this->Member_model->createMember($finalHandle,$formData['activationCode']);
mkdir("/home/public_html/members/".$finalHandle);
$emailSubject = "Account Activation Required";
$emailContent = $this->load->view('emails/activation.php',$formData,TRUE);
# Initialize mailgun client
$mailgunClient = new Mailgun('my-secret-api-key');
$mailgunDomain = "my-domain.com";
# Send activation email
$response = $mailgunClient->sendMessage($mailgunDomain, array(
'from' => 'Support <[email protected]>',
'to' => 'Member <[email protected]>',
'subject' => 'Welcome to our platform',
'text' => 'Account activation email content'
));
$this->session->set_flashdata('success','Registration successful! Check your email.');
redirect(site_url('signup/success'));
}
}else{
$this->session->set_flashdata('error', '<p>Please fill all required fields!</p>');
}
}
$formData['pageTitle']='Member Registration';
$formData['token']=$token;
$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 suggestions on what might be causing this issue would be really helpful. Thanks!