1084

installing php mailer

Comments for “installing php mailer”
 

Posted by Fin Motolinia on Tuesday 2nd July 2024 at 15:35 GMT

Greetings Trongate Community!

Followed the video in mod market and getting this error:
Mailer Error: error_log
Warning: Cannot modify header information - headers already sent by (output started at /home/finsgllc/public_html/modules/mailman/controllers/Mailman.php:827) in /home/finsgllc/public_html/engine/tg_helpers/url_helper.php on line 78

Tried following this thread (https://trongate.io/help_bar_threads/display/yH7EbBBrGSwk59jw)

Did more research and found this
(https://trongate.io/help_bar_threads/display/5dqYteUUBb7GWsmb)

Where "Tonygreen" states "I did manage to get the phpMailer library working by removing the namespace references and "requiring" the classes "

But I dont know what this means, so I am learning about namespaces now to try "Tonygreen"s fix. I also am learning about postman and checking headers. Any suggestions? or better questions I should be asking?
Level One Member

Fin Motolinia

User Level: Level One Member

Date Joined: 18/01/2024

Posted by DaFa on Tuesday 2nd July 2024 at 21:37 GMT

Hi Fin,

If Dan doesn't step in, I'll post a solution in the next day or so.
Founding Member

DaFa

User Level: Founding Member

Date Joined: 30/11/2018

Posted by DaFa on Saturday 6th July 2024 at 00:11 GMT

Hi Fin,

Sorry for my slow response - it has been a rather busy week for me doing my day job.

I see Dan hasn't responded, he might be busy too.

OK... I've had a look at this and see a few issues with the Mailman module.
1. once you install both the 'Simple Members' module and Dan's 'Mailman' module you have to set up a few things, which you have most likely done, but let me make things clear if you or others have deviated:
    • In the 'Mailman' module add your email credentials to the '_send_my_email()' function:
function _send_my_email($data){

        $subject = $data['subject'];
        $to = $data['target_email'];
        
        if($data['msg_html'] == ''){
            $msgHTML = '<p>No message here. Sorry...</p>';
            $msgPLAIN = 'No message here. Sorry...';
        }else{
            $msgHTML = $data['msg_html'];
            $msgPLAIN = $data['msg_plain'];

        }
        
        $mail = new Mailman();  
        $mail->isSMTP();
        
        //Enable SMTP debugging
        //SMTP::DEBUG_OFF = off (for production use)
        //SMTP::DEBUG_CLIENT = client messages
        //SMTP::DEBUG_SERVER = client and server messages
        $mail->SMTPDebug = false; //SMTP::DEBUG_SERVER;
        $mail->SMTPSecure = 'tls';
        $mail->Host = 'smtp.gmail.com';
        $mail->Port = 587;         
        $mail->SMTPAuth = true;
        $mail->Username = '[email protected]';
        $mail->Password = 'your_password';   
        $mail->setFrom('[email protected]', 'your_name');  
        $mail->addReplyTo('[email protected]','No Reply');
        $mail->addAddress($to, '');        
        $mail->Subject = $subject;

        $mail->isHTML(true);
        $mailContent = $msgHTML;
        $mail->Body = $mailContent;

        $mail->AltBody = $msgPLAIN; 
        //json($mail, true);
        if ($mail->send()) {

            } else {
                echo 'Mailer Error: ' . $mail->Debugoutput = 'error_log';
                redirect('mailer/error_from_send_my_email');
        }       

    }
    • In the 'Members' module add the following to:
function _send_activate_account_email($member_obj, $activate_url) {
        //send an email inviting the user to goto the $reset url
        $data['subject'] = 'Confirm Your Account';
        $data['target_name'] = $member_obj->first_name . ' ' . $member_obj->last_name;
        $data['member_obj'] = $member_obj;
        $data['activate_url'] = $activate_url;
        $data['target_email'] = $member_obj->email_address;
        $data['view_module'] = 'members';
        $data['msg_html'] = $this->view('msg_confirm_account', $data, true);
        $msg_plain = str_replace('</p>', '\\n\\n', $data['msg_html']);
        $data['msg_plain'] = strip_tags($msg_plain);
        //add your own code below this line for sending email
        $this->module('mailman');
        $this->mailman->_send_my_email($data);
    }

    function _send_password_reset_email($member_obj, $reset_url) {
        //send an email inviting the user to goto the $reset url
        $data['subject'] = 'Password Reset';
        $data['target_name'] = $member_obj->first_name . ' ' . $member_obj->last_name;
        $data['member_obj'] = $member_obj;
        $data['reset_url'] = $reset_url;
        $data['target_email'] = $member_obj->email_address;
        $data['view_module'] = 'members';
        $data['msg_html'] = $this->view('msg_password_reset_invite', $data, true);
        $msg_plain = str_replace('</p>', '\\n\\n', $data['msg_html']);
        $data['msg_plain'] = strip_tags($msg_plain);
        //add your own code below this line for sending email
        $this->module('mailman');
        $this->mailman->_send_my_email($data);
    }
NOTE: Dan's README.md has the wrong module name in the 'Members' module setup so use the above one and don't forget to add the missing semicolon Dan missed in it too
$this->module('mailer');
$this->mailer->send_my_email($data);
    • If you followed the above it should all just work
    • If you followed Dan's video tutorial, and changed this to true
$mail->SMTPDebug = true; //SMTP::DEBUG_SERVER;
You will see a whole bunch of debug info on your screen and if you have warnings set to true in you PHP setup you will also see the following warning you reported above:
Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\b1\modules\mailman\SMTP\controllers\SMTP.php:251) in D:\xampp\htdocs\b1\engine\tg_helpers\url_helper.php on line 78
NOTE - I am seeing a different line number that you (251 in SMTP.php) where you are seeing it in 'Mailman.php' at line 827... I think there might be some missing code when Dan stripped PHPMailer down and also referenced the 'mailer' instead of 'mailman' on the redirects. It's up to you to try to find these, but for me, I'd stick to installing PHPMailer from my previous post (https://trongate.io/help_bar_threads/display/e94SHS7RnyaE7qe6) as it has been updated since Dan's Mailman which uses '6.5.3' and now it's current version is '6.9.1' and then create an emailer function that can pass $data[] array as Dan had done or wait for Dan to release fixes to the 'Mailman' module.

This comment was edited by DaFa on Saturday 6th July 2024 at 00:13 GMT

Founding Member

DaFa

User Level: Founding Member

Date Joined: 30/11/2018

Posted by Fin Motolinia on Monday 8th July 2024 at 21:55 GMT

Ok, took a couple days but I got rid of mailman and got a fresh PHPMailer working with the Members Module. No header issue. but I got cannot connect to smtp issue.
I have used Composer to install PHPMailer in Vendor folder and have not moved it to assets in my "basemodule" as suggested by Tonygreen but left it where installed by composer.

This line in the _send_my_email() method in my mail module is the culprit and needs to be commented out to get rid of connect error
$mail->isSMTP();


It was hinted at when Dan said he didnt include smtp in the mailman module I think.

Along with this at the top of my php file to import classes as per dafas recommendation (https://trongate.io/help_bar_threads/display/5dqYteUUBb7GWsmb) members is working now with PHPMailer like butter!
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
//use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require('../vendor/autoload.php');

class Mail extends Trongate{

I am working with CentoOS on a hostgator vps
Thank you Trongate Community for all the guidance!

This comment was edited by Fin Motolinia on Tuesday 9th July 2024 at 11:49 GMT

Level One Member

Fin Motolinia

User Level: Level One Member

Date Joined: 18/01/2024

×