Welcome Guest, Not a member yet? Register   Sign In
email sending issue with CI4
#1

Hi guys,
iam getting error while sending email using CI4.please help
controller code : 
Code:
$email1 = \Config\Services::email();
$email1->setFrom($data['from_email'], 'Password reset');
                $email1->setTo($postData['resetpaas-email']); 
                $email1->setSubject('Reset your password');
                $email1->setMessage("hi");
                $email1->send();

Code:
<?php
namespace Config;

use CodeIgniter\Config\BaseConfig;

class Email extends BaseConfig
{

/**
* @var string
*/
public $fromEmail;

/**
* @var string
*/
public $fromName;

/**
* @var string
*/
public $recipients;

/**
* The "user agent"
*
* @var string
*/
public $userAgent = 'CodeIgniter';

/**
* The mail sending protocol: mail, sendmail, smtp
*
* @var string
*/
public $protocol = 'smtp';

/**
* The server path to Sendmail.
*
* @var string
*/
public $mailPath = '/usr/sbin/sendmail';

/**
* SMTP Server Address
*
* @var string
*/
public $SMTPHost='mail.smtpserver';

/**
* SMTP Username
*
* @var string
*/
public $SMTPUser = "username";

/**
* SMTP Password
*Cm4rt2?1
* @var string 
*/
public $SMTPPass = "pwd";

/**
* SMTP Port
*
* @var integer
*/
public $SMTPPort = 465;

/**
* SMTP Timeout (in seconds)
*
* @var integer
*/
public $SMTPTimeout = 10;

/**
* Enable persistent SMTP connections
*
* @var boolean
*/
public $SMTPKeepAlive = false;

/**
* SMTP Encryption. Either tls or ssl
*
* @var string
*/
public $SMTPCrypto = 'ssl';

/**
* Enable word-wrap
*
* @var boolean
*/
public $wordWrap = true;

/**
* Character count to wrap at
*
* @var integer
*/
public $wrapChars = 76;

/**
* Type of mail, either 'text' or 'html'
*
* @var string
*/
public $mailType = 'html';

/**
* Character set (utf-8, iso-8859-1, etc.)
*
* @var string
*/
public $charset = 'utf-8';

/**
* Whether to validate the email address
*
* @var boolean
*/
public $validate = false;

/**
* Email Priority. 1 = highest. 5 = lowest. 3 = normal
*
* @var integer
*/
public $priority = 3;

/**
* Newline character. (Use “\r\n” to comply with RFC 822)
*
* @var string
*/
public $CRLF = "\r\n";

/**
* Newline character. (Use “\r\n” to comply with RFC 822)
*
* @var string
*/
public $newline = "\r\n";

/**
* Enable BCC Batch Mode.
*
* @var boolean
*/
public $BCCBatchMode = false;

/**
* Number of emails in each BCC batch
*
* @var integer
*/
public $BCCBatchSize = 200;

/**
* Enable notify message from server
*
* @var boolean
*/
public $DSN = false;

}

Code:
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
Date: Fri, 20 Aug 2021 17:40:25 +0400



Content-Type: multipart/alternative; boundary="B_ALT_611fb0c9480738.26688342"

This is a multi-part message in MIME format.
Your email application may not support this format.

--B_ALT_611fb0c9480738.26688342
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
 
Reply
#2

PHP Code:
do it like me work on live host 


<?php

namespace Config;

use 
CodeIgniter\Config\BaseConfig;

class 
Email extends BaseConfig
{
 
/**
 * @var string
 */
 
public $fromEmail='[email protected]';

 
/**
 * @var string
 */
 
public $fromName='admin';

 
/**
 * @var string
 */
 
public $recipients;

 
/**
 * The "user agent"
 *
 * @var string
 */
 
public $userAgent 'CodeIgniter';

 
/**
 * The mail sending protocol: mail, sendmail, smtp
 *
 * @var string
 */
 
public $protocol 'smtp';

 
/**
 * The server path to Sendmail.
 *
 * @var string
 */
 
public $mailPath '/usr/sbin/sendmail';

 
/**
 * SMTP Server Address
 *
 * @var string
 */
 
public $SMTPHost='mail.admin.ir';

 
/**
 * SMTP Username
 *
 * @var string
 */
 
public $SMTPUser='[email protected]';

 
/**
 * SMTP Password
 *
 * @var string
 */
 
public $SMTPPass='X04r0U2ikd';

 
/**
 * SMTP Port
 *
 * @var integer
 */
 
public $SMTPPort 25;

 
/**
 * SMTP Timeout (in seconds)
 *
 * @var integer
 */
 
public $SMTPTimeout 5;

 
/**
 * Enable persistent SMTP connections
 *
 * @var boolean
 */
 
public $SMTPKeepAlive false;

 
/**
 * SMTP Encryption. Either tls or ssl
 *
 * @var string
 */
 
public $SMTPCrypto '';

 
/**
 * Enable word-wrap
 *
 * @var boolean
 */
 
public $wordWrap true;

 
/**
 * Character count to wrap at
 *
 * @var integer
 */
 
public $wrapChars 76;

 
/**
 * Type of mail, either 'text' or 'html'
 *
 * @var string
 */
 
public $mailType 'text';

 
/**
 * Character set (utf-8, iso-8859-1, etc.)
 *
 * @var string
 */
 
public $charset 'UTF-8';

 
/**
 * Whether to validate the email address
 *
 * @var boolean
 */
 
public $validate false;

 
/**
 * Email Priority. 1 = highest. 5 = lowest. 3 = normal
 *
 * @var integer
 */
 
public $priority 3;

 
/**
 * Newline character. (Use “\r\n” to comply with RFC 822)
 *
 * @var string
 */
 
public $CRLF "\r\n";

 
/**
 * Newline character. (Use “\r\n” to comply with RFC 822)
 *
 * @var string
 */
 
public $newline "\r\n";

 
/**
 * Enable BCC Batch Mode.
 *
 * @var boolean
 */
 
public $BCCBatchMode false;

 
/**
 * Number of emails in each BCC batch
 *
 * @var integer
 */
 
public $BCCBatchSize 200;

 
/**
 * Enable notify message from server
 *
 * @var boolean
 */
 
public $DSN false;





PHP Code:
  $email = \Codeigniter\Config\Services::email();
            $emailConfig = new \Config\Email();
            $email->initialize($emailConfig);
            $email->setFrom($emailConfig->fromEmail$emailConfig->fromName);
            $email->setTo($contacting['email']);
            $email->setSubject(lang('Commmon.apiEvent.emailReply') . ' ' $contacting['title']);
            $email->setMessage($this->request->getJSON()->reply);
            $result $email->send();

            //      print_r(  $email->printDebugger()); 
Enlightenment  Is  Freedom
Reply
#3

(This post was last modified: 08-20-2021, 11:38 AM by adil.)

(08-20-2021, 09:49 AM)paliz Wrote:
PHP Code:
do it like me work on live host 


<?php

namespace Config;

use 
CodeIgniter\Config\BaseConfig;

class 
Email extends BaseConfig
{
 
/**
 * @var string
 */
 
public $fromEmail='[email protected]';

 
/**
 * @var string
 */
 
public $fromName='admin';

 
/**
 * @var string
 */
 
public $recipients;

 
/**
 * The "user agent"
 *
 * @var string
 */
 
public $userAgent 'CodeIgniter';

 
/**
 * The mail sending protocol: mail, sendmail, smtp
 *
 * @var string
 */
 
public $protocol 'smtp';

 
/**
 * The server path to Sendmail.
 *
 * @var string
 */
 
public $mailPath '/usr/sbin/sendmail';

 
/**
 * SMTP Server Address
 *
 * @var string
 */
 
public $SMTPHost='mail.admin.ir';

 
/**
 * SMTP Username
 *
 * @var string
 */
 
public $SMTPUser='[email protected]';

 
/**
 * SMTP Password
 *
 * @var string
 */
 
public $SMTPPass='X04r0U2ikd';

 
/**
 * SMTP Port
 *
 * @var integer
 */
 
public $SMTPPort 25;

 
/**
 * SMTP Timeout (in seconds)
 *
 * @var integer
 */
 
public $SMTPTimeout 5;

 
/**
 * Enable persistent SMTP connections
 *
 * @var boolean
 */
 
public $SMTPKeepAlive false;

 
/**
 * SMTP Encryption. Either tls or ssl
 *
 * @var string
 */
 
public $SMTPCrypto '';

 
/**
 * Enable word-wrap
 *
 * @var boolean
 */
 
public $wordWrap true;

 
/**
 * Character count to wrap at
 *
 * @var integer
 */
 
public $wrapChars 76;

 
/**
 * Type of mail, either 'text' or 'html'
 *
 * @var string
 */
 
public $mailType 'text';

 
/**
 * Character set (utf-8, iso-8859-1, etc.)
 *
 * @var string
 */
 
public $charset 'UTF-8';

 
/**
 * Whether to validate the email address
 *
 * @var boolean
 */
 
public $validate false;

 
/**
 * Email Priority. 1 = highest. 5 = lowest. 3 = normal
 *
 * @var integer
 */
 
public $priority 3;

 
/**
 * Newline character. (Use “\r\n” to comply with RFC 822)
 *
 * @var string
 */
 
public $CRLF "\r\n";

 
/**
 * Newline character. (Use “\r\n” to comply with RFC 822)
 *
 * @var string
 */
 
public $newline "\r\n";

 
/**
 * Enable BCC Batch Mode.
 *
 * @var boolean
 */
 
public $BCCBatchMode false;

 
/**
 * Number of emails in each BCC batch
 *
 * @var integer
 */
 
public $BCCBatchSize 200;

 
/**
 * Enable notify message from server
 *
 * @var boolean
 */
 
public $DSN false;





PHP Code:
  $email = \Codeigniter\Config\Services::email();
            $emailConfig = new \Config\Email();
            $email->initialize($emailConfig);
            $email->setFrom($emailConfig->fromEmail$emailConfig->fromName);
            $email->setTo($contacting['email']);
            $email->setSubject(lang('Commmon.apiEvent.emailReply') . ' ' $contacting['title']);
            $email->setMessage($this->request->getJSON()->reply);
            $result $email->send();

            //      print_r(  $email->printDebugger()); 

Still getting the error.it was working fine yesterday.i didnt change any code or anything.
When i use public $SMTPCrypto = '';


Code:
public $SMTPCrypto = '';
public $SMTPPort = '25';
getting error
Code:
hello: 452 syntax error (connecting)
The following SMTP error was encountered: 452 syntax error (connecting)
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
Reply
#4

check your smtp mail log, its your server maybe not CI4
Reply
#5

(08-20-2021, 11:53 AM)ikesela Wrote: check your smtp mail log, its your server maybe not CI4

hi,
where is the smtp mail log in wamp server?
Reply
#6

Hi,

If you are working locally trying to send email with wamp, I suggest you to try this service during your developpement : https://mailtrap.io/
I get (a lot of) issues with email sending and the problem was not CI4 or wamp but providers resctrictive policies trying to fight against spam.
Once your app is ok, it should work as well online with your providers smtp settings.

Hope this will help !
Reply




Theme © iAndrew 2016 - Forum software by © MyBB