CodeIgniter Forums
Mail problem [SOLVED] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Mail problem [SOLVED] (/showthread.php?tid=81507)



Mail problem [SOLVED] - JustJohnQ - 03-13-2022

Hello all,

Below code works without problems:
PHP Code:
public function phpMail(){
$to      '[email protected]';
$subject 'the subject';
$message 'hello Codeigniter 2';
$headers 'From: [email protected]';

mail($to$subject$message$headers);

Using Codeigniter's built-in mail function:
PHP Code:
public function ciMail() {
 
$email = \Config\Services::email();
$email->setFrom('[email protected]''Name');
$email->setTo('[email protected]');
$email->setSubject('Email Test');
$email->setMessage('Testing the email class.');

if(!
$email->send(false)):
echo 
$email->printDebugger();
endif;

I get an error:
"Unable to send email using PHP mail(). Your server might not be configured to send mail using this method."
$fromEmail and $fromName are set in App\Config\Email.php. $protocol is set to 'mail'.

Any help is aprreciated.

John


RE: Mail problem - captain-sensible - 03-14-2022

last time i read about using php mail() function i also read about various security concerns. I just use : https://github.com/PHPMailer/PHPMailer

The good thing about it , is that on developing a web on local host , PHPMailer works and so i can play about with it also developing spam detector code so , i don't get too much spam.

I have the PHPMailer directory at the same level as the app, public dirs etc and use autoload class so all the classes are found . Then in my controller that i use i have at the beginning

Code:
<?php namespace App\Controllers;

use CodeIgniter\Controller;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\OAuth;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
use \App\Andy\CheckSpam;
use \App\Andy\Utility;
use CodeIgniter\I18n\Time;



RE: Mail problem - JustJohnQ - 03-15-2022

Thanks for your suggestion. I will try it out soon. In the mean time I solved the particular problem with the CI mail fuction. The server on which the application is running doesn't accept the fith argument sending mail ('-f '). I temporarily changed the mail function until I can implement a better solution.