Welcome Guest, Not a member yet? Register   Sign In
Mail problem [SOLVED]
#1

(This post was last modified: 03-15-2022, 02:08 AM by JustJohnQ.)

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
Reply
#2

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;
CMS CI4     I use Arch Linux by the way 

Reply
#3

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB