I am using codeigniter framework.
I have written code for sending emails like this:
$this->emailcomm->sendemail($data) ;
but it is in loop. It is working for only once. It is not return any response after send the email.
I have tried like below:
for($i=0; $i<count($keyarray);$i++)
{
$data=array(
'to' => $keyarray[$i],
'from' => 'test' ,
subject' => 'test Order',
'message' => ('Please see attached sales order placed ),
'attach' =>$array[$keyarray[$i]]['pdf']
);
$this->emailcomm->sendhtml_email($data);
}
in emailcomm library i have written like below:
function sendhtml_email($info)
{
$this->CI->email->clear();
$this->CI->email->from('reports#gmail.com','Test Reports');
$this->CI->email->to($this->to);
$this->CI->email->subject($this->subject);
$this->CI->email->message($this->message);
$this->CI->email->attach($path.$this->attach,'attachment');
if($this->CI->email->send())
{
$this->CI->email->clear(TRUE);
return 1;
}
}
It send the email only once. I need it run howmany times in loop. And it does not give any output like above return 1 after send the email. Please advice me.
Please try this:
for($i=0; $i<count($keyarray);$i++)
{
$data=array(
'to' => $keyarray[$i],
'from' => 'test' ,
subject' => 'test Order',
'message' => '(Please see attached sales order placed )',
'attach' =>$array[$keyarray[$i]]['pdf']
);
$this->emailcomm->sendhtml_email($data);
}
In emailcomm library i have written like below:
public function sendhtml_email($info)
{
$this->CI->load->library('email');
//$this->CI->email->clear(); //No Need
$this->CI->email->from('reports#gmail.com','Test Reports');
$this->CI->email->to($this->to);
$this->CI->email->subject($this->subject);
$this->CI->email->message($this->message);
$this->CI->email->attach($path.$this->attach,'attachment');
if($this->CI->email->send())
{
/*$this->CI->email->clear(TRUE);
return 1;*/ //No need
}
}
Ref:
https://www.codeigniter.com/user_guide/libraries/email.html
Related
I am new in Laravel development. I am sending an email to agencies which is approved and email is not null and if agencies email is null then get customer email for send email, But I got this error https://flareapp.io/share/DPygyxQ5#F57
I have tried to figure out where is the issue using echo pre in every steps. I am using smtp for sending email.
If you think that is there issue in smtp so if user register itself then email is successfully sent to user.
Here is code
// Get agency details
$agencies = Agency::where('status', 2)->get();
$property = Property::where('property_id', $id)->first();
if($agencies->isNotEmpty())
{
foreach($agencies as $agency)
{
if($agency->email != null)
{
$agency_name = $agency->name;
$agency_email = $agency->email;
$property_slug = $property->slug;
$property_link = route('property.detail', $property_slug);
Mail::send('emails.user.agency.mail_to_agency_after_property_approve',
[
'agency_email' => $agency_email,
'agency_name' => $agency_name,
'property' => $property,
'property_link' => $property_link,
],
function($message) use ($agency_email)
{
$message->to($agency_email);
$message->subject('Fresh Property Listing Update');
});
}
else
{
$customer = Customer::select('customer_id', 'first_name', 'last_name', 'customer_email')->where('customer_id', $agency->customer_id)->first();
$agency_name = $customer->first_name.' '.$customer->last_name;
$agency_email = $customer->customer_email;
$property_slug = $property->slug;
$property_link = route('property.detail', $property_slug);
Mail::send('emails.user.agency.mail_to_agency_after_property_approve',
[
'agency_email' => $agency_email,
'agency_name' => $agency_name,
'property' => $property,
'property_link' => $property_link,
],
function($message) use ($agency_email)
{
$message->to($agency_email);
$message->subject('Fresh Property Listing Update');
});
}
}
}
I am using laravel admin, and I am trying to send emails at a specific time. I pass this datetime data into the first argument of later method
"date" => Carbon #1576722840 {#543 ▼
date: 2019-12-19 02:34:00.0 UTC (+00:00) }
However, it doesnt work as I expected. it randomly sends emails.
$form->saved(function (Form $form) {
if ($form->model()->to === '4') {
$emails = EmailAddress::all();
} else {
$emails = EmailAddress::where('user_type', $form->model()->to)->get();
}
$data = ['id' => $form->model()->id, 'title' => $form->model()->title, 'from' => $form->model()->from, 'body' => $form->model()->body, 'date' => $form->model()->schedule_date, 'is_html' => $form->model()->is_html];
foreach ($emails as $email) {
$url = URL::signedRoute('unsubscribe',['email_address_id' => $email->id]);
Mail::to($email)->later($data['date'],new MagazineMail($data,$url));
}
});
return $form;
}
As I understood it, if I want to send a mail at a specific time, I should just pass a datetime into the first argement, so I have no idea why my code does not work.
I made sure my env file is correct and set QUEUE_CONNECTION=database.
Hello I setup mailgun correctly. and did form contact us.
To send the message to my email by this code
public function send_contact_us()
{
$data = array(
'name' => Request::get('name'),'email'=>Request::get('email'),'subject'=> Request::get('subject'));
$client_m=Request::get('message');
$data_message=array('message_c'=>$client_m);
echo "we above MAIL";
Mail::send('emails.message',$data_message, function ($message)use ($data) {
$message->from($data['email'], 'E-SHOPPER');
$message->to("azharnabil013#yahoo.com")->subject($data['subject']);
});
return view('contact_us', array('title' => 'Welcome', 'description' => '', 'page' => 'contact_us','subscribe'=>'','sent'=>"Message has been sent successfuly"));
}
The code run correctly and this page display
But when I check my email I didn't find any message
I don't know why this problem .please, anyone help me.
Columns (both datatype time):
Start
End
End cannot be before start.
$validator
->requirePresence('end', 'create')
->notEmpty('end')
->add('end', [
'time' => [
'rule' => 'time',
'message' => 'end can only accept times.'
],
'dependency' => [
'rule' => [$this, 'endBeforeStart'],
'message' => 'end can not be before start.'
],
]);
If it is a PUT request which only contains end, the model will need to query the existing record to compare against start. If it is a PUT which contains both then it need to validate against the intended new parameter.
How does cakePHP3 do this?
private function endBeforeStart($fieldValueToBeValidated, $dataRelatedToTheValidationProcess)
{
//What goes here?
}
I can't seem to find any examples of doing this online.
I'm not quite sure and haven't tested it, but maybe this gives you some hints:
$validator
->add('end', [
'endBeforeStart' => [
'rule' => function ($value, $context) {
// If it's a POST (new entry):
if ( $context['newRecord'] == '1' ) {
// Do your comparison here
// Input values are e.g. in $context['data']['starttime']
// If end is before start:
return false;
}
// If it's a PUT (update):
else {
// If starttime is not in $context['data']['starttime']
// check for the old value in $getOldEntry
$getOldEntry = $this->getOldEntry( $context['data']['id'] );
// And do your comparison here...
// If end is before start:
return false;
}
return true;
},
'message' => 'end can not be before start.' ],
])
public function getOldEntry($id = null) {
return $this->get($id);
}
I'm also not sure if the last function has to be private or public...
I'm developing an web app using codeigniter. When I try to click
an image (using detail method), it doesn't include the ID of the image in the link.
I have tried many times, but it still doesn't work. I've even run the same project on another team member's PC, but it still doesn't work on my PC.
Here's the code:
public function detail($url_title, $id = '') {
// Get user logged in id
$user_id = $this->auth->userid();
// Decode url id
$id = decode_safe_url(#$id);
// Get survey master info
// division 0 mean survey, status 0 is not publish
$survey = $this->egsurveymaster->get(array('id' => #$id, 'division' => '1', 'status != ' => "0"));
// Redirect if product review is not exist
if (!#$survey) {
redirect('andrasurvey');
}
// Update read count
if (isset($_COOKIE['eblo_pcid'])) {
$this->egsurveymaster->count_read(#$id, $_COOKIE['andra_pcid']);
}
// Title
$this->template->title = asset_title('Andra Survey - ' . #$survey->title);
// Vars
$vars = array(
'contents' => array(
'master_id' => #$survey->id,
'review' => $this->_overviewContent(#$survey->id, #$survey),
),
'snsContents' => array(
'title' => #$survey->title,
'image' => asset_url(#$survey->image),
'url' => base_url('andrasurvey/detail/' . url_title(#$survey->title) . '/' . encode_safe_url(#$survey->id)),
'content' => character_limiter(strip_tags(#$survey->content, 150)),
'keywords' => trim(#$survey->title) . ', ',
'username' => 'andraadmin',
),
);
// Content
$this->template->content->view(asset_content('detail'), #$vars);
// publish the template
$this->template->publish();
}
When I click the image, this is what I get:
http://localhost:1234/andrasurvey/survey/detail/umur-anda-yang-seharusnya/
I really need your help,
Thank you.