Welcome Guest, Not a member yet? Register   Sign In
Email smtp: mail not send - no error
#2

Let me write here the codes which work perfectly for me.

1. Upload your PHPMailer folder into your root folder, beside your App, public etc folders

2. Go to Config / Autoload, find your lines starting with public $psr4 =  (the line might be 42) :

PHP Code:
public $psr4 = [
        
APP_NAMESPACE => APPPATH// For custom app namespace
        
'Config'      => APPPATH 'Config',
        
'App' => APPPATH// To ensure filters, etc still found

        
'Forms' => ROOTPATH.'forms',
        
'PHPMailer\\PHPMailer'=> ROOTPATH.'PHPMailer/src' 
    
]; 

3. On your Controller, include this just before your class ControllerName extends BaseController {...

PHP Code:
//mailer

use PHPMailer\PHPMailer\PHPMailer;
use 
PHPMailer\PHPMailer\OAuth;
use 
PHPMailer\PHPMailer\Exception;
use 
PHPMailer\PHPMailer\SMTP

4. mailing starts

PHP Code:
//mailing starts

$member_email $this->request->getVar('member_email');
$name $this->request->getVar('member_name');
$my_email '[email protected]'

$mail = new PHPMailer();

$mail->isSMTP();
$mail->Timeout 20;
$mail->SMTPDebug 0;
//Set the hostname of the mail server
$mail->Host 'this might be your server name. Check your mail settings';
$mail->Port 587;
$mail->SMTPSecure 'tls';
$mail->SMTPAuth true;
$mail->Username "[email protected]";  
$mail
->Password "Password";  
$mail
->setFrom('[email protected]''Welcome to my website ');
$mail->addAddress($member_email'');

//Set the subject line
        
$message 'Thanks for registering. You can login on our 
<a href="http://mywebsite.com/my_folder/login" target="_blank">Login</a> page.<br><br>Regards,<br>My Website.com'
;
  
$name_greeting 
'Dear ' .$name;

$mail->isHTML(true);
    $mail->Subject 'My Web Site - Welcome.';
    $mail->Body    "$name_greeting,<br /><br />$message";
    $mail->CharSet 'utf-8';

$mail->send();

    
$session = \Config\Services::session();
    
$session->setFlashdata('success''Thanks for registering. You wil receive an email etc.');
    return 
redirect()->to(site_url('en/login'));

//mailing ends 
Reply


Messages In This Thread
RE: Email smtp: mail not send - no error - by demyr - 05-08-2021, 09:00 AM



Theme © iAndrew 2016 - Forum software by © MyBB