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
Well, I'll take that as a conformation that error had nothing to do with the replacement functions discussed in this thread and just something to do with class.phpmailer.

I'm not sure if I should use it with that error, however it did seem to be working. I thought that the original function was working again, but after just getting many "Undelivered Mail Returned To Sender" letters in my inbox, I'm pretty sure it's still not working.

I just tested it with the first example again. Mail sends fine, but I still get that strange error.

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

The only problem it seems to be causing now is that it doesn't send email to every user in the groups I've specified in Mass Email, but instead only to one.

I used your example too, Lopalong, but I don't know what language file I am supposed to specify. I'll try it again when I figure that out.
He used require instead of require_once

fix'd
function my_mail($to, $subject, $message, $from="", $charset="", $headers="")
{
    require_once("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();
} 
This is confusing. Can someone show me the exact code that I am replacing with the modified code above?
Replace the whole function of my_mail.

Then enter your FROM, HOST, USERNAME, and PASSWORD for your SMTP server.

Be sure to upload the mailer class too.
The mail sent using this function turned up with empty sender-fields, so I modified it to use the admin-address if no other was specified. The first lines of my "my_mail" now reads:


require_once MYBB_ROOT."inc/class.phpmailer.php";
$mail = new PHPMailer();

global $db, $mybb, $lang;

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

if(empty($from))
{
     $from = $mybb->settings['adminemail'];
}
Quote:Language string failed to load: connect_host

Does anything need to be edited in class.phpmailer.php? Or calss.smtp.php?
Pages: 1 2