MyBB Community Forums

Full Version: Setup automated email on mybb with zoho email guide
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Its a pain in the lime to setup email on your own, mybb phpmail and smtp mail are not working. So I have decided to modify core php files to use phpmailer lib instead.

1. Register an email from zoho, its free!

2. SSH into your server and install composer, make sure it is global accessible.

3. cd to your web root directory

4. install phpmailer by copy pasting follow code to ssh 

composer require phpmailer/phpmailer

5. modify core files on inc/functions.php and add

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

on the top of the script just after <?php

the result should be...

<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

6. on the same file press ctrl+f to find the lines "function my_mail($to, $subject, $message, $from="", $charset="", $headers="", $keep_alive=false, $format="text", $message_text="", $return_email="")"

function my_mail($to, $subject, $message, $from="", $charset="", $headers="", $keep_alive=false, $format="text", $message_text="", $return_email="")
{
	global $mybb;
	static $mail;

	// Does our object not exist? Create it
	if(!is_object($mail))
	{
		require_once MYBB_ROOT."inc/class_mailhandler.php";

		if($mybb->settings['mail_handler'] == 'smtp')
		{
			require_once MYBB_ROOT."inc/mailhandlers/smtp.php";
			$mail = new SmtpMail();
		}
		else
		{
			require_once MYBB_ROOT."inc/mailhandlers/php.php";
			$mail = new PhpMail();
		}
	}

	// Using SMTP based mail
	if($mybb->settings['mail_handler'] == 'smtp')
	{
		if($keep_alive == true)
		{
			$mail->keep_alive = true;
		}
	}

	// Using PHP based mail()
	else
	{
		if($mybb->settings['mail_parameters'] != '')
		{
			$mail->additional_parameters = $mybb->settings['mail_parameters'];
		}
	}

	// Build and send
	$mail->build_message($to, $subject, $message, $from, $charset, $headers, $format, $message_text, $return_email);
	return $mail->send();
}

to

function my_mail($to, $subject, $message,$a=true,$b=true,$c=true,$d=true,$e=true,$f=true,$g=true)
{

	if (!$to) {
		return false;
	}

	require MYBB_ROOT . 'vendor/autoload.php';

	$mail2 = new PHPMailer(true);                               

	$mail2->SMTPDebug = 0;                                  
	$mail2->isSMTP();                                      
	$mail2->Host = 'smtp.zoho.com';    
	$mail2->SMTPAuth = true;                               
	$mail2->Username = '[email protected]';                 
	$mail2->Password = 'mypasswordispassword'; 
	$mail2->SMTPSecure = 'ssl';                             
	$mail2->Port = 465;                                    
	$mail2->XMailer    = '  '; 
    //Recipients 
	$mail2->setFrom('[email protected]','abc');
    $mail2->addAddress($to);     // Add a recipient
    $mail2->addReplyTo('[email protected]','abc');
    //Content
    $mail2->isHTML(true);                                   
    $mail2->Subject = $subject;
    $mail2->Body    = $message;


    if($mail2->send())
    {
    	return true;
    }
}

And.. thats it! Now you get the email running like charm!

 [Image: attachment.php?aid=42169]