[SOLVED] New form issue. Original post solved.

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
bullzi
Forum Newbie
Posts: 15
Joined: Thu May 29, 2008 1:38 pm

[SOLVED] New form issue. Original post solved.

Post by bullzi »

I apologize if I'm posting in the wrong place, but I didn't know whether to reply to my original post with a new issue or start over. Obviously, I chose to start over. I solved my original issue, which was a "whitespace" issue and being new to PHP and Swift, quite an accomplishment for me.

My new problem is the following error message upon submitting my form:
Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/bullzico/public_html/bullzi_swift/Swift.php on line 36
I looked in Swift.php and don't have a clue to what this is relating to other than it is line 36 and "version number". I haven't seen any instruction to make additions or changes in Swift.php.
My handler code is attached:

Code: Select all

<?php
//Check if the required fields were sent
// Redirect back to the form if not
if (empty($_POST["name"]) || empty($_POST["email"]) || empty($_POST["organization"]) || empty($_POST["phone"]))
{
//redirect back to form
header("Location: support.php?error=not_enough_info"); //This should really be an absolute URL if you know it
exit();
}
//Copy into global variables
$name = $_POST["name"];
$organization = $_POST["organization"];
$phone = $_POST["phone"];
$email = $_POST["email"];
$fax = $_POST["fax"];
$address = $_POST["address"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
$body = $_POST["comments"];
$title = $_POST["subject"];
//Validate the email address using a regex
if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email))
{
    header("Location: /support.php?error=invalid_email");
    exit();
}
//Check if an attachment was uploaded
$file_path = false;
$file_name = false;
$file_type = false;
if (!empty($_FILES["attachment"]["tmp_name"]))
{
    if ($_FILES["attachment"]["error"])
    {
        //Redirect if the upload has failed
        header("Location: /support.php?error=upload_failed");
        exit();
    }
    $file_path = $_FILES["attachment"]["tmp_name"];
    $file_name = $_FILES["attachment"]["name"];
    $file_type = $_FILES["attachment"]["type"];
}
//Everything looks ok, we can start Swift
require_once "bullzi_swift/Swift.php";
require_once "bullzi_swift/Swift/Connection/Sendmail.php";
//Enable disk caching if we can
if (is_writable("/tmp"))
{
    Swift_CacheFactory::setClassName("Swift_Cache_Disk");
    Swift_Cache_Disk::setSavePath("/tmp");
}
//Try to connect using /usr/sbin/sendmail -bs
$swift = new Swift(new Swift_Connection_Sendmail());
//Create the sender from the details we've been given
$sender = new Swift_Address($email, $name);
//Create the message to send
$message = new Swift_Message($title);
$message->attach(new Swift_Message_Part($name));
$message->attach(new Swift_Message_Part($organization));
$message->attach(new Swift_Message_Part($phone));
$message->attach(new Swift_Message_Part($fax));
$message->attach(new Swift_Message_Part($address));
$message->attach(new Swift_Message_Part($city));
$message->attach(new Swift_Message_Part($state));
$message->attach(new Swift_Message_Part($zip));
$message->attach(new Swift_Message_Part($body));
//If an attachment was sent, attach it
if ($file_path && $file_name && $file_type)
{
    $message->attach(
        new Swift_Message_Attachment(new Swift_File($file_path), $file_name, $file_type));
}
//Try sending the email
$sent = $swift->send($message, "me@mycompany.tlb", $sender);
//Disconnect from SMTP, we're done
$swift->disconnect();
if ($sent)
{
    header("Location: /thanks.html");
    exit();
}
else
{
    header("Location: /support.php?error=sending_failed");
    exit();
}
?>
I hope there's help out there, as this is out of my reach. Happy to provide more information if needed.
Thanks
PS - Should I mark a previous post as solved in some way?
Last edited by bullzi on Mon Jun 02, 2008 10:03 am, edited 1 time in total.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: New form issue. Original post solved.

Post by califdon »

bullzi wrote:Should I mark a previous post as solved in some way?
Yes, please, we appreciate indicating that a problem has been solved. After logging in, just go to your original post and click on Edit, then add the word [SOLVED] to the Subject.

Sorry, I can't help you with Swiftmailer issues. Never used it.
bullzi
Forum Newbie
Posts: 15
Joined: Thu May 29, 2008 1:38 pm

Re: New form issue. Original post solved.

Post by bullzi »

Thanks. Will post "solved".
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: New form issue. Original post solved.

Post by Chris Corbyn »

This error is because you're trying to use PHP5 code in a PHP4 environment. Download the PHP4 version of Swift Mailer or (preferably) upgrade to PHP5.
bullzi
Forum Newbie
Posts: 15
Joined: Thu May 29, 2008 1:38 pm

Re: New form issue. Original post solved.

Post by bullzi »

Thanks Chris.
My mistake. I read the server was running 5, but its running 4.4.8. I must have read the mysql line.
I originally installed for 4 but switched to the 5 download after misreading. Will adjust and see what happens.
Very impressed with your efforts and intimidated by your knowledge.
bullzi
Forum Newbie
Posts: 15
Joined: Thu May 29, 2008 1:38 pm

Re: New form issue. Original post solved.

Post by bullzi »

Switching back to the version for PHP4 solved this error message.
Post Reply