CodeIgniter Forums

Full Version: sending email via gmail
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to send emails with gmail attachment but codeigniter always gives me the error:
to: 555 5.5.2 Syntax error. n2sm18426280wra.89 - gsmtp
The following SMTP error was encountered: 555 5.5.2 Syntax error. n2sm18426280wra.89 - gsmtp
in any case, however, the email arrives correctly at its destination!
below is the code I use to send

PHP Code:
function sendEmail($to ''$subject  ''$body ''$attachment '') {
 
       
    $controller 
=& get_instance();
 
       
    $controller
->load->helper('path'); 

 
   // Configure email library

 
   $config = array();
 
   $config['useragent'           "CodeIgniter";
 
   $config['mailpath'            "/usr/bin/sendmail"// or "/usr/sbin/sendmail"
 
   $config['protocol'            "smtp";
 
   $config['smtp_host'           "ssl://smtp.gmail.com";
 
   $config['smtp_port'           "465";
 
   $config['smtp_timeout'        '30';
 
   $config['smtp_user'           "[email protected]";
 
   $config['smtp_pass'           "password";
 
   $config['mailtype'            'html';
 
   $config['charset'             'utf-8';
 
   $config['newline'             "\r\n";
 
   $config['crlf'                "\n";
 
   $config['wordwrap'            TRUE;
 
   $config['allowed_types'       'pdf';
 
   $config['max_size'            '100000';

 
   $controller->load->library('email');

 
   $controller->email->initialize($config);   
    $controller
->email->set_newline("\r\n");
 
   $controller->email->set_crlf("\r\n");
 
   if($attachment != '')
 
   {
 
       $controller->email->attach(base_url()."uploads/interventi/" .$attachment);
 
   }

 
   $controller->email->from('[email protected]','Test Test');
 
   
    $controller
->email->to($to,$to);
 
   
    $controller
->email->subject('Test message');

 
   $controller->email->message($body);    


 
   if($controller->email->send()){
 
       $this->session->set_flashdata('msg''Email sent correctly');
 
   }
 
   
    else
    
{
 
       show_error($controller->email->print_debugger());
 
       
    
}

PHP Code:
$config = array();

$config['protocol'    'smtp'  // 'mail', 'sendmail', or 'smtp'
$config['smtp_host'   'smtp.gmail.com'
$config['smtp_port'   465,
$config['smtp_user'   '[email protected]',
$config['smtp_pass'   'password',
$config['smtp_crypto' 'ssl'  //can be 'ssl' or 'tls' for example
$config['smtp_timeout'] = '30'   //in seconds 
(05-02-2019, 06:46 AM)php_rocs Wrote: [ -> ]@emanuele.zamengo

Try this link: https://stackoverflow.com/questions/4421...ntax-error

thanks in this way it works !!
@emanuele.zamengo

Awesome, glad I could assist.
(05-02-2019, 10:28 AM)php_rocs Wrote: [ -> ]@emanuele.zamengo

Awesome, glad I could assist.

I ask one last thing:
if I manually set the recipient address in this way
PHP Code:
Controller-> Email-> to ('<[[email protected]>']test.test@gmail.com>'[/email]); 

everything works correctly
if instead I compose it like this:
PHP Code:
Controller-> Email-> to ('<'. $ To'>'); 

from error anyway!
where's the problem?
@emanuele.zamengo,

Then this tells me that only the first solution works and maybe there was a change to what is acceptable by Google.
(05-03-2019, 05:15 PM)php_rocs Wrote: [ -> ]@emanuele.zamengo,

Then this tells me that only the first solution works and maybe there was a change to what is acceptable by Google.

yes!