PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
anthony88guy
Forum Contributor
Posts: 246 Joined: Thu Jan 20, 2005 8:22 pm
Post
by anthony88guy » Mon Jun 19, 2006 2:36 pm
I've downloaded the latest Swift Mailer (Swift-1.2.2.zip) and created a function to use across my site.
php version: PHP 4.4.1
Function:
Code: Select all
function swiftmailer($username, $email, $subject, $message, $members)
{
$members = ($members == 0) ? 'members' : '';
require($members . '/includes/swift_mailer/Swift.php');
require($members . '/includes/swift_mailer/Swift_SMTP_Connection.php');
$connection = new Swift_SMTP_Connection('mail.blah.com');
$mailer = new Swift($connection, $_SERVER['SERVER_NAME']);
//If anything goes wrong you can see what happened in the logs
if (!$mailer->hasFailed())
{
$mailer->addPart($message, 'text/html');
$mailer->send(
'"' . $username . '" <' . $email . '>',
'"NO REPLY" <blah@blah.com>',
$subject
);
$mailer->close();
$emaillog = '<br>Successfully sent email.<br>';
}
else
{
$emaillog = '<br>Unsuccessfully sent email.<br>';
}
//echo all for debugging
echo $emaillog;
echo $swiftwerror = "The mailer failed to connect. Errors: ".print_r($mailer->errors, 1).". Log: ".print_r($mailer->transactions, 1);
}
Tried:
Code: Select all
swiftmailer('blahh', 'my@email.com', 'subject', 'body', 0);
Output:
Parse error: parse error, unexpected T_STRING in /home/blah/public_html/members/includes/swift_mailer/Swift.php on line 65
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Mon Jun 19, 2006 2:44 pm
Have you downloaded PHP4 version of Swift? There are separate versions for PHP5 and PHP4.
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Mon Jun 19, 2006 2:52 pm
Yep, i bet you downloaded the PHP5 version.
Note to d11wgt...maybe you shuld highlight the different version better in the menu on your site...even i downloaded the wrong version and i am supposed to know what i am doing
anthony88guy
Forum Contributor
Posts: 246 Joined: Thu Jan 20, 2005 8:22 pm
Post
by anthony88guy » Mon Jun 19, 2006 3:18 pm
Maybe Chris should make this size 72 font:
Filenames with the "-php4" postfix are for PHP4, the other files are for PHP5.
Works flawlessly now, I guess it would help if I installed the right version.
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Tue Jun 20, 2006 6:50 am
I'm not kidding I get loads of emails for this too. I've just responded to three this morning. Maybe if I add the words "-php5" to the PHP5 versions. The thing is that I'm a pretty big PHP5 enthusiast and would love to see more hosts making use of it.
Is there a way to get PHP4 to display a more descriptive error of my own such as "You seem to be using the PHP5 version in a PHP4 environment?" - oh yes of course... php_version() silly me
I'll add that at the top of the script.
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Tue Jun 20, 2006 7:17 am
Code: Select all
function require_version($ver1, $ver2 = false, $message = 'Failed required PHP version check') {
if(
!$ver2 ?
version_compare($ver1, phpversion(), '<=') :
(version_compare($ver1, phpversion(), '<=') && version_compare(phpversion(), $ver2, '<='))
) {
return;
}
die($message);
}
// for php5
require_version('5.0.0');
// for php4.4.2
require_version('4.4.2');
// for php versions between 4.1.0 && 4.3.2 (inclusive)
require_version('4.1.0', '4.3.2');
// with custom error message
require_version('5.0.0', false, 'This package runs only on PHP5 , it seems you have PHP v' . phpversion());
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Tue Jun 20, 2006 7:23 am
Weirdan wrote: Code: Select all
function require_version($ver1, $ver2 = false, $message = 'Failed required PHP version check') {
if(
!$ver2 ?
version_compare($ver1, phpversion(), '<=') :
(version_compare($ver1, phpversion(), '<=') && version_compare(phpversion(), $ver2, '<='))
) {
return;
}
die($message);
}
// for php5
require_version('5.0.0');
// for php4.4.2
require_version('4.4.2');
// for php versions between 4.1.0 && 4.3.2 (inclusive)
require_version('4.1.0', '4.3.2');
// with custom error message
require_version('5.0.0', false, 'This package runs only on PHP5 , it seems you have PHP v' . phpversion());
Awesome, cheers. I might just that (with credit to you if you wrote it?).
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Tue Jun 20, 2006 7:29 am
Yup, it's mine.
anthony88guy
Forum Contributor
Posts: 246 Joined: Thu Jan 20, 2005 8:22 pm
Post
by anthony88guy » Tue Jun 20, 2006 8:18 am
Neat script. This should clear up some confusion.