i'm begginer in this and i found with this problem...i wan to send email from my localhost to a gmail account (this last can change for a hotmail), but first i want to prove for a gmail account.
i had configure my email.php and it seems like this:
public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'xxxxx#gmail.com',
'password' => 'xxxx',
'transport' => 'Smtp'
);
and in my controller i have this
public function compras()
{
$Email = new CakeEmail();
$Email->config('gmail');
$this->loadModel('Soya');
$this->paginate = array(
'conditions' => array('Grupo.categoria' => 'Soya','Grupo.subcategoria' => 'Productor de Oleaginosas'),
'limit' => 25
);
$this->set('soyas', $this->paginate('Soya'));
$this->Email->to = 'xxxx#gmail.com';
$this->Email->subject = 'Include your subject';
$this->Email->from = 'xxxx#gmail.com';
//$this->Email->template = 'template'; // file name template.ctp will be included in /views/elements/email/text/template.ctp
$this->Email->delivery = 'smtp';
if ($this->Email->send()
) {
return true;
} else {
echo $this->Email->smtpError;
}
}
but when i compile the errors appears
**Indirect modification of overloaded property SoyasController::$Email has no effect [APP/Controller/SoyasController.php, line 124]
Error: Call to a member function send() on a non-object **
please help!!!thanks a lot!!!
public function compras()
{
$Email = new CakeEmail();
$Email->config('gmail');
$this->loadModel('Soya');
$this->paginate = array(
'conditions' => array('Grupo.categoria' => 'Soya','Grupo.subcategoria' => 'Productor de Oleaginosas'),
'limit' => 25
);
$this->set(array('soyas', $this->paginate('Soya')));
$Email->to('xxxx#gmail.com');
$Email->subject('Include your subject');
$Email->from('xxxx#gmail.com');
if ($Email->send())
{
return true;
} else {
echo $this->Email->smtpError;
}
}
Related
i want to get read receipt of emails that we send by codeigniter emails.
i am not able to get how to use it in codeigniter mails.
i know we should use X-confirm reading but its not working in codeigniter.
public function formcomplete()
{
$appid = $this->uri->segment(3);
$datan = $this->product->fetchtransaction($appid);
$txnid = $datan[0]['txn_id'];
$email = $datan[0]['email'];
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'email-smtp.eu-west-1.amazonaws.com',
'smtp_port' => 587,
'smtp_crypto' => 'tls',
'smtp_user' => 'user',
'smtp_pass' => 'pass',
'mailtype' => 'text',
'charset' => 'utf-8',
);
$datanew = array(
'firstname' => $datan[0]['firstname'],
);
$this->email->initialize($config);
$this->email->set_mailtype("html");
$this->email->set_newline("\r\n");
$this->email->set_crlf("\r\n");
$subject = "Complete Your Partially Filled Application-".$appid."";
$data['datan'] = $datanew;
$mesg = $this->load->view('email/reminder/form_complete',$data,true);
$this->email->to($email);
$this->email->AddCustomHeader( "X-Confirm-Reading-To: notifications#mymail.com" );
$this->email->from('support#mail.com','Company Email');
$this->email->subject($subject);
$this->email->message($mesg);
$this->email->send();
$baseurl = "https://www.getyourevisa.com/admin/application/view/";
$completeurl = $baseurl.$appid;
//redirect('admin/application/view/' . $appid);
echo ("<script LANGUAGE='JavaScript'>
window.alert('Form Complete Reminder Successfully Sent');
window.location.replace('$completeurl');
</script>");
}
i have used below line, but its not working, i think there should be some other way to write this code.
$this->email->AddCustomHeader( "X-Confirm-Reading-To: notifications#mymail.com" );
For CI version 3, it should be
$this->email->set_header('X-Confirm-Reading-To', 'name#email.com');
For CI version 4
$email->setHeader('X-Confirm-Reading-To', 'name#email.com');
I am working with CakePHP version 1.3.13.
Here, I want to send mail. So I have written code like this :
function send_mail_to_client()
{
$text = "sending mail";
App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail();
$Email->from(array('sachingarala.v2047#gmail.com' => 'My Site'));
$Email->to('nisargbhavsar24#gmail.com');
$Email->subject('Test mail');
$Email->send($text);
}
But, mail is not send to the destination. So what is the wrong in this code?
How can I resolve this problem?
Add the configs after initialization i.e. $Email = new CakeEmail(); like
$Email->config(array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'my#gmail.com',
'password' => 'secret',
'transport' => 'Smtp'
);
My codeigniter script will not send emails. I have tested sendmail on xampp with a native PHP email script and it works. This is definitely a problem with CI or my config. The send() function always returns false and the print_debugger() function is always blank. Am I doing something wrong?
<?php
$config = array(
'mailtype' => 'html',
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_user' => 'myaccount#gmail.com',
'smtp_pass' => '#############',
'smtp_port' => '465'
);
$this->load->library('email', $config);
$this->email->from($this->stg['site_name']);
$this->email->to($this->input->post('email_address'));
$this->email->subject('Your Account Email Has Been Changed');
$data = array(
'activation_code' => $this->member->activation_code
);
$message = $this->load->view('emailTemplates/change_email', $data, true);
$this->email->message($message);
if(!$this->email->send()){
$this->template->overallHeader('Email Failed');
$data = array(
'title' => 'Email Sending Failed',
'message' => 'The system failed to dispatch the email message to your new email address. Because of this, the email address on your account has NOT been changed. '.$this->email->print_debugger()
);
$this->load->view('errorBody', $data);
} else {
//do stuff
}
I have also tried static strings instead of the form input variables as the to and from, etc.
I've got a problem with sending mail using CakePHP. Everythings giong well, but i didn't receive any single mail , i tired to send to 2 different emails .
//WebsitesController.php
App::uses('AppController','Controller');
App::uses('CakeEmail','Network/Email');
class WebsitesController extends AppController
{
public $helpers = array('Html','Form','Session');
public $components = array('Email','Session');
public function contact()
{
$this->set('dane', $this->Website->findById(4));
}
public function contact_email()
{ /* all data is taken from contact.ctp, I debuged all data below and it's correct */
$useremail = $this->data['Website']['useremail'];
$usertopic = $this->data['Website']['usertopic'];
$usermessage = $this->data['Website']['usermessage'];
$Email = new CakeEmail();
$Email->from(array($useremail => ' My Site'));
$Email->to('wigan#mail.com');
$Email->subject($usertopic); // all data is correct i checked several times
$Email->send($usermessage);
if($Email->send($usermessage))
{
$this->Session->setFlash('Mail sent','default',array('class'=>'alert alert-success'));
return $this->redirect(array('controller'=>'websites','action'=>'contact'));
}
$this->Session->setFlash('Problem during sending email','default',array('class'=>'alert alert-warning'));
}
}
//contact.ctp
<fieldset>
<?php
echo $this->Form->create('Website',array('controller'=>'websites','action'=>'contact_email'));
echo $this->Form->input('useremail',array('class'=>'form-control'));
echo $this->Form->input('usertopic',array('class'=>'form-control'));
echo $this->Form->input('usermessage',array('class'=>'form-control'));
echo $this->Form->submit('Send',array('class'=>'btn btn-default'));
echo $this->Form->end();
?>
</fieldset>
all seems to be fine, even if statement in function contact_email is approved.
configuration ( i'm working on localhost, xampp, netbeans 7.4)
public $smtp = array(
'transport' => 'Smtp',
'from' => array('site#localhost' => 'My Site'),
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
'log' => false,
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
try this, you didn't set the config
public function contact_email()
{ /* all data is taken from contact.ctp, I debuged all data below and it's correct */
$useremail = $this->data['Website']['useremail'];
$usertopic = $this->data['Website']['usertopic'];
$usermessage = $this->data['Website']['usermessage'];
$Email = new CakeEmail();
$Email->config('smtp')
->emailFormat('html')
->from($useremail)
->to('wigan#mail.com')
->subject($usertopic); // all data is correct i checked several times
if($Email->send($usermessage))
{
$this->Session->setFlash('Mail sent','default',array('class'=>'alert alert-success'));
return $this->redirect(array('controller'=>'websites','action'=>'contact'));
} else {
$this->Session->setFlash('Problem during sending email','default',array('class'=>'alert alert-warning'));
}
}
Please follow the steps:
step 1: In this file (app\Config\email.php)
add this:
public $gmail = array(
'transport' => 'Smtp',
'from' => array('site#localhost' => 'Any Text...'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => 'youremail#example.com',
'password' => 'yourPassword',
'client' => null,
'log' => false,
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
step 2: Add an email template (app\View\Emails\html\sample.ctp)
<body>
<h1>Email Testing: <?php echo $first_name?></h1>
</body>
step 3: Change the code in your method as shown below:
public function send_my_email() {
App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail();
$Email->config('gmail'); //configuration
$Email->emailFormat('html'); //email format
$Email->to('receiveremail#ex.com');
$Email->subject('Testing the emails');
$Email->template('sample');//created in above step
$Email->viewVars(array('first_name'=>'John Doe' ));//variable will be replaced from template
if ($Email->send('Hi did you receive the mail')) {
$this->Flash->success(__('Email successfully send on receiveremail#ex.com'));
} else {
$this->Flash->error(__('Could not send the mail. Please try again'));
}
}
I've been trying to send emails with Pear on xampp through Gmail, and after spending hours setting it all up and figuring out all the errors I was getting, I thought I was so close, until I started getting this error:
controller action
public function automail() {
App::uses('CakeEmail', 'Network/Email');
$ret_msg = null;
try {
$is_call_email = true;
$subject = "case detail";
$comment = "Ready to Review";
$email_to = "exmaple#gmail.com";
if ($is_call_email == true) {
$email_to = str_replace(' ', '', $email_to);
$email_addresses = preg_split('/[;,]/', $email_to);
$this->log($is_call_email,'bool');
$email = new CakeEmail();
$email->from(array($this->Session->read('Auth.User.email') => $this->Session->read('Auth.User.name')))
->to($email_addresses)
->subject($subject)
->send($comment);
$this->log($subject,'subject');
}
} catch (Exception $ex) {
$ret_msg = $ex->getMessage();
$this->log($ex->getLine(), 'emailError');
}
$this->log('Return msg is = ' . $ret_msg, 'shared');
return;
in email.php
<?php
class EmailConfig {
public $default = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'example#gmail.com', //example#gmail.com
'password' => 'secret',
'transport' => 'Smtp',
'from' => array('exampe#gmail.com' => 'Nam Email'),
'log' => true
);
}
from and to both are same email addresses because i was send in my account for testing...
please help me or any advice for how to send email using cakephp....
You need to specify $email->config. Like:
$email->config('default')
->from(array($this->Session->read('Auth.User.email') => $this->Session->read('Auth.User.name')))
->to($email_addresses)
->subject($subject)
->send($comment);