I made a website for a club of my university and I used PHPMailer. When I try it in my own server, it works perfectly. However after I upload the site to the school's FTP, my PHPMailer is not working. I contacted the school IT and they said: "The version of PHP on the server is 4.3.9. Codes that you wrote must be suitable for it. In server's error logs we got the following error: PHP Parse error: parse error, unexpected '{' in mailer.php on line 23". I checked my codes billion times but I cannot solve the problem on that. Here is my code:
<?
if(!empty($_POST['sender_mail'])
|| !empty($_POST['sender_name'])
|| !empty($_POST['sender_surname'])
|| !empty($_POST['sender_major'])
|| !empty($_POST['sender_schoolyear'])
|| !empty($_POST['sender_id']))
{
phpinfo();
require_once('class.phpmailer.php');
include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$smail = $_POST['sender_mail'];
$name = $_POST['sender_name'];
$surname = $_POST['sender_surname'];
$major = $_POST['sender_major'];
$schoolyear = $_POST['sender_schoolyear'];
$id = $_POST['sender_id'];
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telli ng the class to use SMTP
try { // Here is 23th line
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "xxxxx@gmail.com"; // GMAIL username
$mail->Password = "xxxxxxx"; // GMAIL password
$mail->AddAddress('xxxxx@gmail.com', 'Membership');
$mail->SetFrom('xxxxx@gmail.com', 'GGK');
$mail->Subject = 'New Membership';
$mail->IsHTML(true);
$mail->Body = '<h3>New Membership</h3><br/><i><b>Name: </i></b><i>' . $name . '</i><br/><b><i>Surname: </i></b><i>' . $surname . '</i><br/><b><i>Mail: </i></b><i>' . $smail . '</i><br/><b><i>ID: </i></b><i>' . $id . '</i><br/><b><i>Schoolyear: </b></i><i>' . $schoolyear . '</i><br/><b><i>Major: </b></i><i>' . $major . '</i>';
$mail->Send();
echo "Message Sent OK</p>\n";
} catch (phpmailerException $e) {
echo -1;
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo -1;
echo $e->getMessage(); //Boring error messages from anything else!
}
}
else{
echo -1;
}
?>
Note: I got all values of the form with ajax and post them to mailer.php.
Try/catch is only in PHP5 versions. You'll need to do other error catching (if/else) in order to do the tests.