Page 1 of 1

Swift Mailer...

Posted: Mon Jun 19, 2006 2:36 pm
by anthony88guy
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

Posted: Mon Jun 19, 2006 2:44 pm
by Weirdan
Have you downloaded PHP4 version of Swift? There are separate versions for PHP5 and PHP4.

Posted: Mon Jun 19, 2006 2:52 pm
by JayBird
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 :lol:

Posted: Mon Jun 19, 2006 3:18 pm
by anthony88guy
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.

Posted: Tue Jun 20, 2006 6:50 am
by Chris Corbyn
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 :D I'll add that at the top of the script.

Posted: Tue Jun 20, 2006 7:17 am
by Weirdan

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());

Posted: Tue Jun 20, 2006 7:23 am
by Chris Corbyn
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?).

Posted: Tue Jun 20, 2006 7:29 am
by Weirdan
Yup, it's mine.

Posted: Tue Jun 20, 2006 8:18 am
by anthony88guy
Neat script. This should clear up some confusion.