CodeIgniter/TankAuth forgot_password function sending emails with no content - php

Recently moved an existing CodeIgniter product to its own VPS, everything is working away. However, for some reason a password has been invalidated and when the forgot_password function is run the email arrives with an intact subject line, however, the emails have no content. At all. This is the offending code:
function _send_email($type, $email, &$data) {
$this->load->library('email');
$this->email->from($this->config->item('webmaster_email', 'tank_auth'), $this->config->item('website_name', 'tank_auth'));
$this->email->reply_to($this->config->item('webmaster_email', 'tank_auth'), $this->config->item('website_name', 'tank_auth'));
$this->email->to($email);
$this->email->subject(sprintf($this->lang->line('auth_subject_' . $type), $this->config->item('website_name', 'tank_auth')));
$this->email->message($this->load->view('email/' . $type . '-html', $data, TRUE));
echo $this->load->view('email/' . $type . '-html', $data, TRUE);
$this->email->set_alt_message($this->load->view('email/' . $type . '-txt', $data, TRUE));
$this->email->send();
}
I wrote a short PHP script to send an email using the same CodeIgniter library:
<?php
if(!defined('BASEPATH'))
exit('No direct script access allowed');
class EmailTest extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->library('tank_auth');
$this->lang->load('tank_auth');
}
function sendTest(){
$this->load->library('email');
$this->email->from($this->config->item('webmaster_email', 'tank_auth'), $this->config->item('website_name', 'tank_auth'));
//$this->email->reply_to($this->config->item('webmaster_email', 'tank_auth'), $this->config->item('website_name', 'tank_auth'));
$this->email->to('cameron.j.leafe#gmail.com');
$this->email->subject("Here and There");
$this->email->message("I hear you are an example");
$this->email->send();
echo $this->email->print_debugger();
}
}
?>
That email lands completely fine, and produces this output:
User-Agent: CodeIgniter
Date: Mon, 14 Apr 2014 18:55:55 +1000
From: "EPI Dashboard" <epi#epidashboard.com>
Return-Path: <epi#epidashboard.com>
Reply-To: "epi#epidashboard.com" <epi#epidashboard.com>
X-Sender: epi#epidashboard.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <534ba29b87010#epidashboard.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_534ba29b8708b"
=?utf-8?Q?Here_and_There?=
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ALT_534ba29b8708b
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
I hear you are an example
--B_ALT_534ba29b8708b
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
I hear you are an example
--B_ALT_534ba29b8708b--
The server is a CentOS 6 VPS running postfix and obviously PHP/MySql/Apache.
Any thoughts on what to check or any resources that you can think of would be greatly appreciated.

The PHP.INI file for this server need to have the line:
sendmail_path = /usr/sbin/sendmail -t -i
Which fixed the problem instantly. Not entirely sure as to why parts of the email were showing up and not the body, but it works.

Related

Can't send server emails in CodeIgniter 4

I just hanged up to send server emails.
I'm preparing email sending code like this:
$email_config = Array(
'charset' => 'utf-8',
'mailType' => 'html'
);
$email = \Config\Services::email();
$email->initialize($email_config);
$email->setNewline("\r\n");
$email->setCRLF("\r\n");
$email->setFrom("test#mysite.com", "Sender name");
$email->setTo("receiver#gmail.com");
$email->setSubject("Test message");
$email->setMessage("Hello");
if ($email->send()) {
echo "Email sent!";
} else {
echo $email->printDebugger();
return false;
}
It's showing this error message:
Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.
Date: Thu, 4 Jun 2020 05:21:47 -0500
From: "Sender name" <test#mysite.com>
Return-Path: <test#mysite.com>
Reply-To: <test#mysite.com>
User-Agent: CodeIgniter
X-Sender: test#mysite.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5ed8cb3ba9e500.94682473#mysite.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_5ed8cb3ba9e702.65790334"
=?UTF-8?Q?Test=20message?=
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ALT_5ed8cb3ba9e702.65790334
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Hello
--B_ALT_5ed8cb3ba9e702.65790334
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Hello
--B_ALT_5ed8cb3ba9e702.65790334--
And giving an error in error log:
Email: sendWithMail throwed Use of undefined constant INTL_IDNA_VARIANT_UTS46 - assumed 'INTL_IDNA_VARIANT_UTS46' (this will throw an Error in a future version of PHP)
I want to mention that,
intl extension is enabled in server.
I'm using cPanel.
It was working fine on Codeigniter 3.
The mail function is working with the row method in my server like this:
$to = 'receiver#gmail.com';
$subject = 'Test message';
$message = 'Hello';
$headers = 'From: test#mysite.com' . "\r\n" .
'Reply-To: test#mysite.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
Please help.
Thanks in advance.
You need to setup an MTA on your server (Mail Transfer Agent).
For instance: Postfix or exim, and in some cases nullmailer will do the trick
Possibly you can connect to an SMTP relay of your provider
codeigniter provide alternative types ( Mail, Sendmail and SMTP ) check your cpanel outgoing email configuration or ask your provider to check for php's mail() configuration
I ran into this today, and was surprised to see the library failed out of the box. Seems to be an issue in CI's email lib here:
/**
* Validate email for shell
*
* Applies stricter, shell-safe validation to email addresses.
* Introduced to prevent RCE via sendmail's -f option.
*
* #see https://github.com/codeigniter4/CodeIgniter/issues/4963
* #see https://gist.github.com/Zenexer/40d02da5e07f151adeaeeaa11af9ab36
* #license https://creativecommons.org/publicdomain/zero/1.0/ CC0 1.0, Public Domain
*
* Credits for the base concept go to Paul Buonopane <paul#namepros.com>
*
* #param string $email
*
* #return boolean
*/
protected function validateEmailForShell(&$email)
{
if (function_exists('idn_to_ascii') && $atpos = strpos($email, '#'))
{
$email = static::substr($email, 0, ++$atpos)
. idn_to_ascii(static::substr($email, $atpos), 0, INTL_IDNA_VARIANT_UTS46);
}
return (filter_var($email, FILTER_VALIDATE_EMAIL) === $email && preg_match('#\A[a-z0-9._+-]+#[a-z0-9.-]{1,253}\z#i', $email));
}
I don't have time to investigate what this method is all about (wasted a few hours on this already!), but was able to bypass it and send emails successfully.
Create App/Libraries/Email.php to override the problematic method:
<?php namespace App\Libraries;
class Email extends \CodeIgniter\Email\Email{
protected function validateEmailForShell(&$email){
return TRUE;
}
}
Then make the service return your subclass in App/Config/Services.php:
public static function email(bool $getShared=TRUE){
return $getShared ? static::getSharedInstance('email') : new \App\Libraries\Email();
}
Got a solution from CI forum.
From phpinfo() > intl > ICU version was 4.6 in my case. Which is too old.
Updating that to the latest version worked for me.

Not able to send mail in ZF2

call_user_func($this->callable, $to, $subject, $body, $headers, $params);
This was my Function for send mail but it gives following error
{"error-message":"Unable to send mail: Unknown error","error-trace":[{"function":"mailHandler","class":"Zend\Mail\Transport\Sendmail","type":"-\u003E","args":["mujahed69#gmail.com","=?UTF-8?Q?Infinia?=","\u003Cdiv\u003Ehello\u003C/div\u003E","Date: Tue, 03 Nov 2015 09:40:43 +0000\nFrom: =?UTF-8?Q?Infinea=20Team?= \u003Cservice#infiniaretail.de\u003E\nMIME-Version: 1.0\nContent-Type: text/html\nContent-Transfer-Encoding: 8bit\n"," -fservice#infiniaretail.de"]},{"file":"/var/www/html/restaurant/vendor/zendframework/zendframework/library/Zend/Mail/Transport/Sendmail.php","line":139,"function":"call_user_func","args":[[{"__className":"Zend\Mail\Transport\Sendmail"}`
use following link, you use custom function. in that function you should be paste same code of this page
http://framework.zend.com/manual/current/en/modules/zend.mail.introduction.html

Swiftmail no E-Mail will be send

I created a contact form in Symfony2. I would like to send it via email and also i want to save the content in the database via Symfony2, for this i created a form. The saving into the database works fine but I never get an email on the production server.
public function createAction(Request $request) {
$entity = new Contact();
$form = $this -> createCreateForm($entity);
$form -> handleRequest($request);
$message = \Swift_Message::newInstance() -> setSubject('Hello Email') -> setFrom('newsletter#donaci.ch') -> setTo('me#joelschmid.ch') -> setBody($this -> renderView('DbeDonaciBundle:Contact:email.html.twig', array('entity' => $entity)));
$this -> get('mailer') -> send($message);
$em = $this -> getDoctrine() -> getManager();
$em -> persist($entity);
$em -> flush();
$this -> get('session') -> getFlashBag() -> add('messageSent', 'Die Nachricht wurde erfolgreich abgeschickt. Wir werden uns sobald als möglich bei dir melden!');
return $this -> render('DbeDonaciBundle:Aboutus:index.html.twig', array('entity' => $entity, 'form' => $form -> createView(), ));
}
Locally this seems to work, if I access the message block in the developer toolbar I have an email ready:
Mailer default (default mailer)
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=utf-8
MIME-Version: 1.0
Date: Tue, 04 Mar 2014 10:54:07 +0100
Message-ID: <725cbd36eaafdc75ede3eeb016a60b1d#localhost>
From: newsletter#donaci.ch
Subject: Hello Email
To: me#joelschmid.ch
A contact enquiry was made by asdf at 2014-03-04 10:54.
Reply-To: asdf#memememe.com
Subject: asdf
Body:
Name: asdf
E-Mail: asdf#memememe.com
Message: asdf
Website: asdf
Also there is no e-mail in the spool if I execute:
php app/console swiftmailer:spool:send
Here is the adjusted configfile with mailjet:
mailer_transport: smtp
mailer_host: in.mailjet.com
mailer_user: 3d32164c00c29asdflkjabf2d1e45b
mailer_password: 342f84sdaj7a3d374eb85523dfad246
locale: en
secret: 34af84cbbb7a3d12li552cfgad246
Any ideas? Thanks in advance for your help guys!
it should be relative to smtp server : if symfony debug shows you the mail, it's definetly this.
Try using a dedicated smtp service such as mailjet ( www.mailjet.com ) to handle your emails sending .

Codeigniter: unable to send email

I have a "Contact Us" page, where if users submit the form. Then email should go to the specified email.
After submiting the form i am getting the Success message ,but i am not seeing any email in my inbox/spam.
I am testing on my live server.
Pelase help me to solve my problem.
My code:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class contact extends CI_Controller {
public function __construct()
{
parent:: __construct();
$this->load->helper('url');
$this->load->helper('form');
$this->load->library('session');
$this->load->library('email');
$this->load->model('shopmodel');
$this->load->model('contactusmodel');
$this->load->library('form_validation');
}
function index()
{
$this->form_validation->set_error_delimiters(' <li class="errorlist">', '</li>')->set_rules('fullname', 'Name','trim|required|min_length[5]|max_length[50]|xss_clean');
$this->form_validation->set_error_delimiters('<li class="errorlist">', '</li>')->set_rules('countryname', 'Country','trim|required|min_length[2]|max_length[50]|xss_clean');
$this->form_validation->set_error_delimiters('<li class="errorlist">', '</li>')->set_rules('email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_error_delimiters('<li class="errorlist">', '</li>')->set_rules('contactdetails', 'Contact Details','trim|required|min_length[40]|max_length[2000]|xss_clean');
$data=$this->contactusmodel->contactusmodel();
$data["query"] = $this->shopmodel->getshopdetailsById(199);//taking data as shop id 199
if($this->form_validation->run() === FALSE)
{
$data['ffullname']['value'] = $this->input->post('fullname');
$data['fcountryname']['value'] =$this->input->post('email');
$data['femail']['value'] = $this->input->post('countryname');
$data['fcontactdetails']['value'] =$this->input->post('contactdetails');
$this->load->view('contact/contact',$data);
}
else if ($this->form_validation->run() === TRUE)
{
$name=$this->input->post('fullname');
$sendersemail=$this->input->post('email');
$fromcountry=$this->input->post('countryname');
$message=$this->input->post('contactdetails');
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'ashutosh10g#gmail.com',
'smtp_pass' => 'xxxxxxxx',
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_mailtype("html");
$this->email->set_newline("\r\n");
$email_body ="<div>hello world</div>";
$this->email->from('ashutosh10g#gmail.com', 'ddd');
$list = array('ashutosh10g#gmail.com');
$this->email->to($list);
$this->email->subject('Testing Email');
$this->email->message($email_body);
$this->email->send();
echo $this->email->print_debugger();
}
else{
$this->load->view('contact/contact',$data);
}
}
}
?>
What output i am getting is:
[code]
Your message has been successfully sent using the following protocol: mail
From: "ddd"
Return-Path:
Reply-To: "ashutosh10g#gmail.com"
X-Sender: ashutosh10g#gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <513e1456185d4#gmail.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_513e1456185e3"
=?utf-8?Q?Testing_Email?=
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ALT_513e1456185e3
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
hello world
--B_ALT_513e1456185e3
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
<div>hello world</div>
--B_ALT_513e1456185e3--
Maybe you are experimenting a relaying error somtimes the Google Server don't accept relay mail form one MTA to another inbox. Try to test to establish an SMTP dialog to your server an try to send the mail. Here is a simple SMTP dialog example:
http://www.soi.wide.ad.jp/class/20000009/slides/11/6.html
Try to send a mail if the server sends a relay error you should try with another SMTP server. If not maybe is a missconfiguration of your php.
But in my experience gmail always deny the relaying mail for spam and security reasons if the MTA is not a trusted agent.
Another reason may be that you don't have correctly configure DNS Servers and your MTA cannot find the MX Records. Example y your MTA is sendmail it notifies php tha the mail was send succesfully but if you look into sendmail logs you can find that the host is unreachable.

Which method (POST/GET) is using in the SoapClient to send HTTP requests?

I don't know if I'm asking a correct question! But I think its answer will guide me to solve my problem...
I'm trying to call a function by SoapClient,... It is a simplified version of my code:
class SOAP_AuthStruct {
function __construct($user, $pass) {
$this->Username = strval($user);
$this->Password = strval($pass);
}
}
$soap_loc = "SET TO SOAP PATH";
$soap_opts = array (
'location' => $soap_loc,
'style' => SOAP_DOCUMENT,
'use' => SOAP_LITERAL,
'cache_wsdl' => WSDL_CACHE_NONE,
'exceptions' => FALSE,
'trace' => TRUE
);
$testclient = new SoapClient("soapcall.wsdl", $soap_opts);
$soap_auth = new SOAP_AuthStruct("USERNAME", "PASSWORD");
$soap_header = new SoapHeader($soap_ns,'AuthHeader',$soap_auth,FALSE);
// $a_param is filled with essential values
$soap_param = array("CreateTransaction" => $a_param);
try {
$result = $testclient->__soapCall("CreateTransaction", $soap_param, NULL, $soap_header, $output_headers);
echo $testclient->__getLastRequest();
echo "\n\n";
echo $testclient->__getLastResponse();
echo "\n\n";
echo $testclient->__getLastResponseHeaders();
echo "\n\n";
} catch (SoapFault $fault) {
trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
}
I have a sample of correct request format, and the getLastRequest() function shows that the request has the correct format...
but in response I have this Error Message:
HTTP/1.1 405 Method Not Allowed
X-Mashery-Responder: XXXXX.mashery.com
Allow: GET, HEAD, OPTIONS, TRACE
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Tue, 12 Apr 2011 18:34:29 GMT
Accept-Ranges: bytes
Content-Length: 1293
I think (and I'm not sure about it!) that may be SoapClient use POST Method to send request, and I can't find it in the response header: "Allow: GET, HEAD, OPTIONS, TRACE"
Please let me know if you have any solution to my problem! and Also the answer to my question!
Many Thanks in advance for your help and your time ;)
--------------------------------------------
UPDATE:
OK, Now I know that it is sending POST Request!
I added this line to my code (after calling function)
echo $testclient->__getLastRequestHeaders();
and it returned:
POST /RimWebAPI/?api_key=APIKEY&sig=SIGNATURE HTTP/1.1
Host: something.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.1.6
Content-Type: text/xml; charset=utf-8
SOAPAction: "SOAP ACTION"
Content-Length: 2344
I'm still working on it, but I would appreciate any help or quide!
Is the Client HTTP POST calling the directory and not the script? I mean to say that it may be possible that /PATH_TO_API is a directory on the server and your script was index.php in that directory. In that case you will need to append a trailing slash to the POST command so that web-server would return the default document.
What do the server logs say when you get the 405 error? Further, can you send the parameter as a GET instead of POST.

Categories