codeigniter email->send being send twice - codeigniter

i am using codeigniter 2 with the tank_auth library.
in the model named user_model it has an function (_send_email()) to send an email:
function _send_email($type, $email, &$data)
{
$this->load->library('email');
$this->config->set_item('language', 'dutch');
$this->email->set_newline("\r\n");
$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));
$this->email->set_alt_message($this->load->view('email/'.$type.'-txt', $data, TRUE));
if($this->email->send()){
echo "sendit";
}
}
i try to call this function from a controller like this:
public function email($value='')
{
$this->lang->load('tank_auth', 'dutch');
$this->load->model('user_model');
$data = array("site_name" => "site name");
$this->user_model->_send_email('bestelling_geplaatst', "my_email#hotmail.com",$data); // send
}
the problem is that the email is being sent twice to the email adres
anyone who run across this problem an know's where to look for an solution ( or the problem)
More info:
i am trying to make a method in my controller just like the example in the use guide like here: https://www.codeigniter.com/user_guide/libraries/email.html
$this->load->library('email');
$this->email->from('your#example.com', 'Your Name');
$this->email->to('someone#example.com');
$this->email->cc('another#another-example.com');
$this->email->bcc('them#their-example.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
This method also sends the email twice!

The reason is i have the plugin Firebug Lite for Google Chrome. after i deactivated this the page only requested once!
found awnser right here:
https://stackoverflow.com/a/10580841/1108772
Thanks everyone for replying and all you help

First of all, This is wrong approach. Use model function only to interactive with database. The function that sends the mail should be in controller.

Remove this code
if($this->email->send())
{
echo "sendit";
}
from
function _send_email($type, $email, &$data)

Related

How to add more parameter on controller laravel mail

I want to send email using Laravel and success with this code
Mail::to($email)->send(new SendMail($name))
Now I want to send more parameter like subject with this code, but didn't work.
No error message but email not being sent.
Mail::send(new SendMail($name function($message) use ($email){
$message->to($email)->subject('Verify your Account');
}));
Any suggestions? Thanks in advance!
You can use something like that
$template = 'view.email';
$paramets = ['data'=>$data];//Your to value to print in email
$email = 'to#email.com'// to email
$cc = 'cc#email.com' // or null
$toName = 'John Doe' // or null
$subject = 'Verify your Account';
Mail::send($template, $parameters, function($message) use($email,$cc,$toName,$subject) {
$message->from(env('sender'), env('nameSender'));
if($cc) $message->cc($cc);
$message->to($email, $toName)
->subject($subject);
});
I am using a generic method. So i can use this method to all emails that i need to send

Why giving undefined variable in sending Email attachment in Laravel?

I can't pass any variable to Email body from Controller. I have searched many solutions but no is matching with me.
I am using Mailable. But it is empty. I am not sure it is creating problem or not.
public function __construct(){}
public function build(){}
I have tested with dummy Email without passing variable. Email is sending successfully. So, I think there is no problem with configuration.
Function in controller:
public function mail()
{
$info = Invoice::find(65)->first();
// 65 is giving me value. I have checked with dd()
$data = [
'invoice' => $info->invoiceNumber
];
Mail::send(['text'=>'invoice.test'], $data, function($message) use($data){
$pdf = PDF::loadView('invoice.test');
$message->to('example#gmail.com','John Smith')->subject('Send Mail from Laravel');
$message->from('from#gmail.com','The Sender');
$message->attachData($pdf->output(), 'Invoice.pdf');
});
return 'Email was sent';
}
test.blade.php
<h1>It is working!! {{ $invoice }}</h1>
Data sending style is followed by:
Laravel Mail::send how to pass data to mail View
Try adding the $data with the PDF view:
$pdf = PDF::loadView('invoice.test', $data);
But if you want to add an email body content different with the PDF content, try this:
Mail::send([], $data, function($message) use($data){
$pdf = PDF::loadView('invoice.test', $data);
$message->to('example#gmail.com','John Smith')->subject('Send Mail from Laravel');
$message->from('from#gmail.com','The Sender');
$message->setBody('sample mail content');
$message->attachData($pdf->output(), 'Invoice.pdf');
});

How to send email in codeigintier?

I have done a code for send email to a emailid in codeigniter as shown below :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Data extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function insertStu($newStuData){
$stuData = array(
'stu_fullname' => $newStuData['stuFullname'],
'stu_username' => $newStuData['stuUsername'],
'stu_password' => $newStuData['stuPassword'],
'stu_email' => $newStuData['stuEmail'],
'stu_modified_date' => date('y-m-d')
);
$from_email = "annanitababu.19#gmail.com";
$to_email = $newStuData['stuEmail'];
//Load email library
$this->load->library('email');
$this->email->from($from_email, 'Anu');
$this->email->to($to_email);
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
$this->db->insert('sb_stu', $stuData);
return ($this->db->affected_rows() == 1) ? true : false;
}
}
?>
I wanted to send a link of a page as the contents of the message in the send() as a mail to the email id and upon clicking the link in the mail, it should update a particular field in a table which is initially '0' to '1' in the database. Can anyone suggest a solution for this ?
Add link to in the message body and generate encoded unique identification number . The number in link and stored in your db. The user click on that link , decode the unique and match in the table. if found change status 0 to 1.
Example : https://www.amazonsoldout.com/
which also in codeigniter.

When i am trying to send mail from contactUS form getting this error using swiftmailer in Laravel 5.2

when i am trying to send Mail through Contact Us Form receiving this Error
"Address in mailbox given [] does not comply with RFC 2822, 3.6.2."
I try search to find solution but I cannot find one. I edited config/mail.php
public function sendContactInfo(ContactMeRequest $request)
{
$data = $request->only('name', 'email');
$emailto="******#gmail.com";
$data['messageLines'] = explode("\n", $request->get('message'));
Mail::send('publicPages.contactus', $data, function ($message) use ($emailto) {
$message->subject('Contact Us Form: ')
->to(config('blog.contact_email'))
->replyTo($data['email']);
});
return back()
->withSuccess("Thank you for your message. It has been sent.");
}
with configuration file
i am following this tutorial
Laravel Send Mail
use $data['email']
Mail::send('publicPages.contactus', $data, function ($message) use ($emailto,$data['email']) {
$message->subject('Contact Us Form: ')
->to(config('blog.contact_email'))
->replyTo($data['email']);
});

sending email with codeigniter

I have this MODEL and I get the email which I want to send
class Cliente_Model extends CI_Model{
public function getInfo($id){
$this->db->select('*');
$this->db->from('pendientes');
$query = $this->db->get();
if($query->num_rows() > 0)
{
foreach ($query->result_array() as $row)
{
return $row['email'];
}
}
else
{
return FALSE;
}
}
}
CONTROLLER
$this->load->model('cliente_model', 'client');
$clientInfo = $this->client->getInfo($id);
$this->email->from('myemail#gmail.com', 'Demo');
$this->email->to($clientInfo);
$this->email->subject('Email Test');
$this->email->message('your user is '.$clientInfo.' and your password is '.$clave);
$this->email->send();
and I need some help here, I can get the email and it can send it perfectly but in the message I need to send the password also and I don't know how I can get it from the model.
thanks in advance!
Instead of returning '$row['email]' from your model, you should return the whole '$row' which will enable you to get other data from the model and not only the email field.
Not sure, but you might need to use it like this in the controller:
$this->email->message('your user is '.$clientInfo->email.' and your password is '.$clientInfo->passwordField);
Good luck.

Resources