Codeigniter stopped sending mails from gmail smtp on wamp server windows 10 - smtp

The code i am posting was working fine for 2 months. Now, from some reason it stopped sending mails.
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'system#gmail.com',
'smtp_pass' => 'xxxxxxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
//za da mi ispraka na sevisniot mail i da mozam da sledam dali ispraka izvestai dokolku oni stiklirale isprakanje
$this->email->clear(TRUE); //za reset pred sekoe novo prakanje od jamkata
$this->email->set_newline("\r\n");
$this->email->from('doNotReply', '');
$this->email->to('service#gmail.com');
$this->email->subject($subjectStart . ' izvestaj');
$this->email->message('');
$this->email->attach('D:/wamp64/www/dica/assets/iEksel/'. $filename);
if ( ! $this->email->send()){
$myfile = fopen("mail.txt", "a") or die("Unable to open file!");
$txt = $this->email->print_debugger();
fwrite($myfile, $txt);
fclose($myfile);
}
The debugger outputs this errors:
The following SMTP error was encountered: 0 Unable to send data: AUTH LOGINFailed to send AUTH LOGIN command. Error: Unable to send data: MAIL FROM:< doNotReply >< pre>from: The following SMTP error was encountered: < br />Unable to send data: RCPT TO:< br />< pre>to: < /pre>The following SMTP error was encountered: < br />Unable to send data: DATA< br />< pre >data: The following SMTP error was encountered: < br />Unable to send data: User-Agent: CodeIgniter.
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
Does anyone has an idea why this code that worked perfectly for 2 months, now fails to work?

You dont need this smtp code for server-side.
for server-side this much code is enough:
$this->load->library('email');
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->to($this->input->post('emailtxt'));
$this->email->cc($this->input->post('cctxt'));
$this->email->from($fromEmail['user_email']);
$this->email->subject($this->input->post('smailtxt'));
$this->email->message($this->input->post('tamailtxt'));
$this->email->attach($pathfile);
$this->email->send();
and for client side the code you used looks find. Issue must be if smtp user email and password is changed or check php.ini file in wamp.

Instead of smtp used smtps in array.
$config = Array(
'protocol' => 'smtps',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'system#gmail.com',
'smtp_pass' => 'xxxxxxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);

Related

Microsoft 365 SMTP authentication failure [SMTP: Invalid response code received from server

i am getting following error but all settings are correct no issue but advice if someone has done smtp setting of 365 office
connectors are added in admin center and changed the max sp as advised
authentication failure [
SMTP: Invalid response code received from server
(code: 535, response: 5.7.3 Authentication unsuccessful
[LO2P265CA0220.GBRP265.PROD.OUTLOOK.COM]
)
]
here is code:
<?php
require_once "Mail.php";
$from = '<info#domain.com>';
$to = '<dodmaon#domani.com>';
$subject = 'Insert subject here';
$body = "Hello world! this is the content of the email";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'smtp.office365.com',
'SMTPSecure' => 'tls',
'port' => '587',
'StartTLS' => true,
'auth' => true,
'username' => 'info#domain.com',
'password' => '321password'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo '<p>'.$mail->getMessage().'</p>';
} else {
echo '<p>Message successfully sent!</p>';
}
?>
If you are very sure that all settings including Username and Password are correctly configured, then the problem is a Microsoft thing. And how to solve it is this;
you need to login from a browser (https://accounts.live.com) using the username and password you have configured in your application.
While logged in, go to "security and privacy" and look for the link to "recent activity" alternatively, you can just enter this address after logging in to go there directly https://account.live.com/Activity.
From here you should see the attempts from the email you are sending from and click the option "This was me" next/under to it.
Also consider disabling 2step authenticator if on.
When you have completed this, wait a few minutes and then try again.
Let me know if this worked. :)

Yii2 SwiftMailer .eml files created but with wrong names & file_put_contents Permission denied

The problem is when I'm trying to "send" the email it's failing with the message
file_put_contents(/some/path//frontend/runtime/debug/mail/20180413-165142-0679-0633.eml):
failed to open stream: Permission denied
The file is being created but with a slightly different name, for example 20180413-165142-0666-8857.eml (I can see it by time). I have no idea what is going on. Any suggestions?
Config file is simple:
common/main-local.php
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
And sending by this:
Yii::$app->mailer->compose('order', ['order' => $this])
->setTo(Yii::$app->params['adminEmail'])
->setFrom(Yii::$app->params['adminEmail'])
->setSubject('New order #' . $this->id)
->send();
And 'adminEmail' => 'admin#example.com',
Thanks for your attention.

Is my yii2 smtp configuration correct?

I have the following smtp configuration, but I'm not sure since sometimes I face ssl timed out while sending an email.
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
'useFileTransport' => true,
],
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#backend/mail',
'useFileTransport' => false,//set this property to false to send mails to real email addresses
//comment the following array to send mail using php's mail function
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'in-v3.mailjet.com',
'username' => 'a3027c3xxx',
'password' => 'c838779xxx',
'port' => '465',
'encryption' => 'ssl',
],
],
Then I use like this
$message = Yii::$app->mail->compose();
$message->setTo(Yii::$app->params['adminEmail'])
->setFrom(Yii::$app->params['adminEmail'])
->setTo("mymail#gmail.com")
->setSubject('Password Reset')
->setHtmlBody($this->renderAjax('//email/_konten',['hello'=>"To black" ,'konten'=>'this is konten','link'=>Yii::$app->params['baseurl'].'lupapass/chpass?&q=empty','textbutton'=>'Click this link']))
->send();
and the result is sometime I face timed out.
But if I send directly from swiftmailler class like below code it sucessfully send 100 email without any ssl timed out
$transport = \Swift_SmtpTransport::newInstance('in-v3.mailjet.com', 465)
->setUsername('myusername')
->setPassword('s3cr3t')
->setEncryption('ssl');
$mailer = \Swift_Mailer::newInstance($transport);
$message = \Swift_Message::newInstance('Password Reset')
->setFrom(array('no-reply#myweb.com' => 'My Web'))
->setTo(array('some#one.com'))
->setBody($this->renderAjax('//email/_konten',['hello'=>"To black" ,'konten'=>'this is konten','link'=>Yii::$app->params['baseurl'].'lupapass/chpass?&q=empty','textbutton'=>'Click this link']))
->setContentType("text/html")
;
$result = $mailer->send($message);
If you ask how my ssl timed out here is my question link
How to solve Swift_TransportException Connection to ssl Timed Out error?
So I start thinking is this ssl timed out because my configuration? or different sending method? from first example and second example?
in common\config\main-local.php there is a mailer => [] and mail => [] is this neccessary?
an can you please explain what is useFileTransport really?
Thanks in advance.
PS. I have already use any thirdparty and port configuration but still facing ssl timed out issue.
According to Gmail SMTP config when you are using encryption ssl or tls use port 587 instead of 465

Steps to send mail using sendgrid mailer function in yii2?

I am trying to get the mail using sendgrid in Yii 2 but it doesn't seem to work.Can any one tell me steps of sendgrid in yii2 .
You can use https://github.com/bryglen/yii2-sendgrid#yii-2-bryglen-sendgrid
Installation:
composer require --prefer-dist bryglen/yii2-sendgrid "*"
common/config/main.php
'components' => [
...
'sendGrid' => [
'class' => 'bryglen\sendgrid\Mailer',
'username' => 'your_user_name',
'password' => 'your password here',
//'viewPath' => '#app/views/mail', // your view path here
],
...
],
To send an email, you may use the following code:
$sendGrid = Yii::$app->sendGrid;
$message = $sendGrid->compose('contact/html', ['contactForm' => $form]);
$message->setFrom('from#domain.com')
->setTo($form->email)
->setSubject($form->subject)
->send($sendGrid);

Codeigniter Cpanel Mysql Database Setup

I have successfully pushed a codeigniter project to a cpanel console.
Everything seems to be working fine except the database connection.
I believe i have the settings correct but i could be wrong.
Below is my database.php script:
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'instadri_insta',
'password' => 'BL9w;K;ds9MR',
'database' => 'instadri_ver',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
I have the errors below:
A PHP Error was encountered
Severity: Warning
Message: mysqli::real_connect(): (HY000/1044): Access denied for user
'instadri_insta'#'localhost' to database 'instadri_ver'
Filename: mysqli/mysqli_driver.php
Line Number: 202
Backtrace:
File: /home/instadri/application/controllers/Welcome.php Line: 10
Function: __construct
File: /home/instadri/public_html/index.php Line: 319 Function:
require_once
I also get :
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by
(output started at /home/instadri/system/core/Exceptions.php:272)
Filename: core/Common.php
Line Number: 568
Backtrace:
File: /home/instadri/application/controllers/Welcome.php Line: 10
Function: __construct
File: /home/instadri/public_html/index.php Line: 319 Function:
require_once
And Finally :
Unable to connect to your database server using the provided settings.
Filename: controllers/Welcome.php
Line Number: 10
I have taken care of the above.
The new issue now is the smarty template file loading.
I have a controller that does this :
$this->smarty->view('front-theme/index.tpl', $data );
But i get this error:
Unable to load the requested file:
front-theme/index.tpl
My cpanel directory structure is:
public_html
- index.php
application
system public
-_template
-_cache
-front-theme
I had the same problem but I have solved it.
Simply upload your CI files to the public html folder, every thing in the CI folder should be uploaded together. so when you open the public folder it should filled with the CI files.
Leave your db settings the same way, but cross-check the values you entered for validity. and finally go to the config.php file and check the base url variable and change to your url link name.
That's it!