MyBB Community Forums

Full Version: SMTP Mail Function with class.phpmailer
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello Everybody,

I use MyBB since yesterday and I found out that my Static IP will be blocked from several Mailservers. Now I rewrite the Mail Function in ('inc/functions.php') and edited the my_mail() function.

all you need is to get the phpmailer Class from here and replace the function in functions.php with the following code

function my_mail($to, $subject, $message, $from="", $charset="", $headers="")
{
	require("class.phpmailer.php");
	$mail = new PHPMailer();
	
	global $db, $mybb, $lang;

	if(empty($charset))
	{
		$charset = $lang->settings['charset'];
	}

	// Build e-mail
	$mail->From = "[email protected]"; // here comes your email address in
	$mail->FromName = $mybb->settings['bbname'];
	$mail->Host     = "smtp.example.com"; // your SMTP Server
	$mail->Mailer   = "smtp"; // SMTP Method
	$mail->SMTPAuth = true;  // Auth Type
	$mail->Username = "your username";
	$mail->Password = "your password";
	$mail->AddAddress($to, "");
	$mail->Subject = $subject;
	$mail->Body = $message;
	
	if(!$mail->Send())
		echo "There has been a mail error sending to ".$to." with Error: ".$mail->ErrorInfo;
	$mail->ClearAddresses();
}

now you are ready to sent emails undependent on your Webserver!

best regardes
troniac[/code]
Maybe, it's better to use a new settings option or a setting in the config file for the authentication of the mailserver Wink
Paretje Wrote:Maybe, it's better to use a new settings option or a setting in the config file for the authentication of the mailserver Wink

I am not one of the Developers! But I agree to you Paretje! The most Spamfilter on Mailservers block several IP Ranges. I guess the Filter includes all Dynamic IP's and ISP IP's. So my Server have a Dynamic IP and the Range of my Provider is blocked on Yahoo, GMX, Hotmail and many other mail providers.

It may be cool if there will be a Mailclient provided by the Forum that can use an external Mail account with Authentification.
Nice...I believe 1.4 is going to have SMTP support though.
well done man
labrocca Wrote:Nice...I believe 1.4 is going to have SMTP support though.
Correct.
Oh, wow, this is exactly what I've been looking for.

Unfortunately, it seems that gmail will still send it straight to the spam filter. At least it gets through now.

Good work. Big Grin
troniac Wrote:It may be cool if there will be a Mailclient provided by the Forum that can use an external Mail account with Authentification.

That would only encourage the mongrels that send spam and unsolicited rubbish with no rDNS to use MyBB as another platform to continue their unwanted trash.

You really want that ?? The code you have in the first post <[email protected]> is hardly a return address. Sad

I suggest that if anone wants to, or needs to try this alternative then they use this code and change my details to thiers, and upload

class.phpmailer.php
class.smtp.php
phpmailer.lang-en.php

To the root / of thier sever. (Not the forum folder.)


	function my_mail($to, $subject, $message, $from="", $charset="", $headers="")
{
	require ("./class.phpmailer.php");
	$mail = new PHPMailer();

	global $db, $mybb, $lang;

		if(empty($charset))
	{
	$charset = $lang->settings['charset'];
}

	// Build e-mail
	$mail->IsSMTP(); // set mailer to use SMTP.
	$mail->SetLanguage("en", ""); // Change to your language and upload the appropriate lang file.
	$mail->From = $from; // this adds who it is from.
	$mail->FromName = $user['username'];  // this adds your "from" name to the email.
	$mail->Host = "mail.m.iinet.net.au"; // your SMTP Server.
	$mail->Mailer = "smtp"; // SMTP Method.
	$mail->SMTPAuth = true; // Authorisation required true / false.
	$mail->Username = "[email protected]"; // your SMTP account.
	$mail->Password = "XXXXXXXXX"; // your SMTP password.
	$mail->AddAddress($to, "");
	$mail->Subject = $subject;
	$mail->Body = $message;
 	$mail->AddReplyTo = $user['username']; // This adds the reply to address.

	if(!$mail->Send())
	echo "There has been a mail error sending to ".$to." with Error: ".$mail->ErrorInfo;
	$mail->ClearAddresses();
}

Which returns a properly formatted email that I doubt any mail server would reject.

Return-Path: <[email protected]>
Delivered-To: [email protected]
Received: (qmail 12555 invoked from network); 3 Nov 2007 10:46:13 -0000
Received: from unknown (HELO outbound.icp-qv1-irony-out1.iinet.net.au) ([203.59.1.108])
          (envelope-sender <[email protected]>)
          by mail.iinet.net.au (qmail-ldap-1.03) with SMTP
          for <[email protected]>; 3 Nov 2007 10:46:13 -0000
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: Ao8CABnuK0dN6FAK/2dsb2JhbAA
X-IronPort-AV: E=Sophos;i="4.21,366,1188748800"; 
   d="scan'208";a="227181753"
Received: from unknown (HELO forum-styles.com) ([77.232.80.10])
  by outbound.icp-qv1-irony-out1.iinet.net.au with ESMTP; 03 Nov 2007 19:46:11 +0900
Date: Sat, 3 Nov 2007 10:46:09 +0000
Return-Path: test <[email protected]>
To: [email protected]
From: test <[email protected]>
Subject: test
Message-ID: <[email protected]>
X-Priority: 3
X-Mailer: PHPMailer [version 1.73]
X-Antivirus: AVG for E-mail 7.5.503 [269.15.19/1106]
Mime-Version: 1.0
So do your modifications just modify the email that's sent or prevent webcrawlers from opening the php files with the modification?

Two questions

1. Couldn't permissions just to be set or some directives in apache.conf be set to protect the php files in the webdir?
2. Would the email sent by your still be rejected based off of the host IP it came from? Mail from my IP gets binned a lot because the CIDR I'm on is on many bulk lists. Is this a good option for me?

Also, for the OP, the mail function was still working, though after a while I began getting an error such as

Fatal error: Cannot redeclare class phpmailer in /usr/share/php/class.phpmailer.php on line 21

The emails still made their way through, however I reverted back to the old one before noticing they did, so it seems as if the actual mailing is working but there's some kind of error going on.
Your questions would be better directed to the class.phpmailer forums.

There is also no need to quote a post immediately above your own post. Use new reply instead. Wink
Pages: 1 2