| |
|
« HOW-TO import/export databases - create backup :: [2.3.0] Custom Pages using /index.php?disp= » |
| Author |
Message |
afwas |

Posted: Thu Jan 31, 2008 07:03 Topic subject: [1.10.3] [2.4.0][2.4.2] HOWTO: use an external mailserver
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 [url=http://www.swiftmailer.org/]swift mailer[/url] in B2evo 1.10.3 and in 2.4.0 rc2. and in B2evolution 2.4.2 This is how to set it up:
- 1) Download swift-smtp from http://www.swiftmailer.org/download
- 2) Rename the folder of the unzipped package to /swift/
== OLD INFORMATION ==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.
- 3) Upload the /swift/ folder to /blogs/htsrv/ on your server
- 4) B2evolution 1.10.3: 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. In B2evolution v 2.4.2 the code is in /blogs/inc/_core/_misc.funcs.php starting at line 1565:
PHP | if( $debug > 1 ) | | { | | if( ! mail( $to, $subject, $message, $headerstring ) ) | | { | | debug_die( 'Sending mail from | | «'.htmlspecialchars($from).'» to | | «'.htmlspecialchars($to).'», Subject | | «'.htmlspecialchars($subject).'» FAILED.' ); | | } | | } | | else | | { | | if( ! @mail( $to, $subject, $message, $headerstring ) ) | | { | | $Debuglog->add( 'Sending mail from | | «'.htmlspecialchars($from).'» to | | «'.htmlspecialchars($to).'», Subject | | «'.htmlspecialchars($subject).'» FAILED.', 'error' ); | | return false; | | } | | } |
by:
PHP | | | global $htsrv_path; | | require_once( $htsrv_path . '/swift-smtp/lib/Swift.php' ); | | require_once( $htsrv_path . '/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 ) | | { | | if( ! $swift->send( $mail, $new_to, $new_from )) | | { | | debug_die( 'Sending mail from | | «'.htmlspecialchars($from).'» to | | «'.htmlspecialchars($to).'», Subject | | «'.htmlspecialchars($subject).'» FAILED.' ); | | } | | } | | else | | { | | 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; | | } | | } |
- 5 I prefer the variables in /conf/_advanced.php. Somewhere put this block after you changed the data:
PHP | | | | | | | | | $smtp_server = 'smtp.server.tld'; | | $smtp_port = 25; | | $smtp_user = 'user'; | | $smtp_password = 'password'; |
[/list:u]
== UPDATE ==
This snippet is obsolete:
If you want to put the Swift mailer files in the /htsrv/ folder (/htsrv/swift-smtp/lib/) you change these lines of the code:
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 |
| Back to top |
|
| |
| |
| |