Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in /home/hemmi3/public_html/blog/inc/items/model/_itemquery.class.php on line 628
Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in /home/hemmi3/public_html/blog/inc/items/model/_itemquery.class.php on line 628
| « Donkey Kong | Conditional CSS through PHP » |
B2evolution 1.10.3 & 2.4.0
HOWTO: use an external SMTP mailserver
Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in /home/hemmi3/public_html/blog/inc/sessions/model/_hit.class.php on line 901
If you cannot send mail through B2evo, probably because your host has disabled PHP's mail() function you must use another mailserver. There are other situations where you deliberately want to use this.
This solution will work with any SMTP server you have access to (can authenticate through username/password).
I had a successful go with Swift mailer in B2evo 1.10.3 and in 2.4.0 rc2. This is how to set it up:
1) Download swift-smtp from http://www.swiftmailer.org/download/ . Unpack and upload the /lib/ folder. I made a directory in /inc/_misc/ called swift-smtp where I put the lib folder. So this looks like /inc/_misc/swift-smtp/lib/. Feel free to add the folder to /htsrv/ where I think it belongs.
2) Open /inc/_misc/_misc.funcs.php and replace lines 2348 - 2362. If you are using B2evo v2.4.0 rc 2 look for this codesnippet in inc/misc/_misc.funcs.php line ~1568.:
if( $debug > 1 )
{ // We agree to die for debugging...
if( ! mail( $to, $subject, $message, $headerstring ) )
{
debug_die( 'Sending mail from
«'.htmlspecialchars($from).'» to
«'.htmlspecialchars($to).'», Subject
«'.htmlspecialchars($subject).'» FAILED.' );
}
}
else
{ // Soft debugging only....
if( ! @mail( $to, $subject, $message, $headerstring ) )
{
$Debuglog->add( 'Sending mail from
«'.htmlspecialchars($from).'» to
«'.htmlspecialchars($to).'», Subject
«'.htmlspecialchars($subject).'» FAILED.', 'error' );
return false;
}
}
by:
//setup swift-smtp
require_once( dirname(__FILE__).'/swift-smtp/lib/Swift.php' );
require_once( dirname(__FILE__).'/swift-smtp/lib/Swift/Connection/SMTP.php' );
global $smtp_server, $smtp_user, $smtp_password, $smtp_port;
$smtp =& new Swift_Connection_SMTP( $smtp_server, $smtp_port);
$smtp->setUsername( $smtp_user );
$smtp->setpassword( $smtp_password );
$swift =& new Swift($smtp);
$mail =& new Swift_Message( $subject, $message);
$to_name = preg_replace( '/^.*?<(.+?)>$/', '$0', $to );
$from_name = preg_replace( '/^.*?<(.+?)>$/', '$0', $from );
$to_email = preg_replace( '/^.*?<(.+?)>$/', '$1', $to );
$from_email = preg_replace( '/^.*?<(.+?)>$/', '$1', $from );
$new_to = new Swift_Address( $to_email, $to_name );
$new_from = new Swift_Address( $from_email, $from_name );
if( $debug > 1 )
{ // We agree to die for debugging...
if( ! $swift->send( $mail, $new_to, $new_from ))
{
debug_die( 'Sending mail from
«'.htmlspecialchars($from).'» to
«'.htmlspecialchars($to).'», Subject
«'.htmlspecialchars($subject).'» FAILED.' );
}
}
else
{ // Soft debugging only....
if( ! @$swift->send( $mail, $new_to, $new_from ))
{
$Debuglog->add( 'Sending mail from
«'.htmlspecialchars($from).'» to
«'.htmlspecialchars($to).'», Subject
«'.htmlspecialchars($subject).'» FAILED.', 'error' );
return false;
}
}
I prefer the variables in /conf/_advanced.php. Somewhere put this block:
/**
* SMTP
* uses swift-smtp
*/
$smtp_server = 'smtp.server.tld';
$smtp_port = 25;
$smtp_user = 'user';
$smtp_password = 'password';
If you want to put the Swift mailer files in the /htsrv/ folder (/htsrv/swift-smtp/lib/) you change these lines of the code:
require_once( dirname(dirname(dirname(__FILE__))).'/htsrv/swift-smtp/lib/Swift.php' );
require_once( dirname(dirname(dirname(__FILE__))).'/htsrv/swift-smtp/lib/Swift/Connection/SMTP.php' );
Once again: I took the /lib/ folder from the package and put it in a custom made /swift-smtp/ folder. You may copy the /lib/ folder from swift-smtp directly to the /htsrv/ folder, but change the path accordingly.
Thanks to dcihon for testing.
Good luck
Trackback address for this post
Feedback awaiting moderation
This post has 1 feedback awaiting moderation...