im using the code of this reference
http://books.google.com.ph/books?id=oXpiVSW5jqkC&pg=PT576&lpg=PT576&dq=app/views/elements/email/html&source=bl&ots=hAf3uDnVRb&sig=rrlbwekcKWfKhvmCvlYdFqC4EHQ&hl=en&sa=X&ei=dVnfUpbdB_GziQfSh4HgCA&ved=0CDAQ6AEwAQ#v=onepage&q=app%2Fviews%2Felements%2Femail%2Fhtml&f=false
i wrote the codes in my appcontroller in my emails_controller
<
lass EmailsController extends AppController {
public $components = array(
'Email' =>array(
'delivery' => 'smpt',
'smtpOptions' => array(
'host' =>
'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'redbaloons#gmail.com',
'password' => '123456789'
)
)
);
then after that i follow this to controllers index()
var $name = 'Emails';
function index() {
$this->Email->recursive = 0;
$this->set('emails', $this->paginate());
$this->Email->to = 'Destination<redbaloons#gmail.com>';
$this->Email->subject = 'Testing The Email component';
$sent('Hello World');
if(!$sent) {
echo 'ERROR: ' . $this->Email->smtpError . '<br />';
}else{
echo 'Email sent!';
}
then just test it, then i got this error
Fatal error: Function name must be a string in C:\xampp\htdocs\reservation\controllers\emails_controller.php on line 24
any configuration just to test this?? Please Help...
The syntax is wrong in this line:
$sent('Hello World');
I don't know exactly what you should be using, but it should be something like:
$sent = $this->Email->send("Hello World");
Related
i need to send emails to all the rows in database table with their corresponsing data. i am able to send single emails by their id, but now i need to send in bulk. i have done in pure php but in codeigniter not able to figure out. how to do this.
my controller is
public function autoformcomplete()
{
$this->load->model('admin/Reminder_model');
$datan = $this->Reminder_model->autoformemail();
//this should be in whileloop, that i am not able to figure out
$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',
);
$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'] = $datan;
$mesg = $this->load->view('email/reminder/form_complete',$data,true);
$this->email->to($email);
$this->email->from('mail#mail.com','My Company');
$this->email->subject($subject);
$this->email->message($mesg);
$this->email->send();
echo "sent";
}
My Model is
public function autoformemail(){
$this->db->order_by('id', 'DESC');
$query = $this->db->get('appstbldata');
return $query->result_array();
}
Just use a foreach loop
public function autoformcomplete() {
$this->load->model( 'admin/Reminder_model' );
$datan = $this->Reminder_model->autoformemail();
foreach ( $datan as $index => $val ) {
// $val now references the current pointer to an element in your $datan array
$email = $val['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',
);
$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'] = $datan;
$mesg = $this->load->view( 'email/reminder/form_complete', $data, true );
$this->email->to( $email );
$this->email->from( 'mail#mail.com', 'My Company' );
$this->email->subject( $subject );
$this->email->message( $mesg );
$this->email->send();
echo "sent";
}
}
I dunno what your point of $data['datan'] = $datan; line is though
I'm new to the zend framework.
I have a code to send a mail and it's working, but the message is not received by the customer side, but it returns that the mail was sent successfully. Can you teach me how to work with zend_email?
public function sendMailStatements($qid,$emails=array()) {
require_once 'Zend/Mail.php';
require_once 'Zend/Mail/Transport/Smtp.php';
try {
$config = array('ssl' => 'ssl',
'port' => 465,
'auth' => 'login',
'host' => '127.0.0.1',
'username' => 'username#gmail.com',
'password' => 'password');
$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
Zend_Mail::setDefaultTransport($transport);
$mail = new Zend_Mail();
$mail->setSubject("Quotation LL Sports Exim");
$body="Dear Sir/Madam<br>Kindly find the attached Quotation and give us your Feed BAck";
$mail->setBodyHtml($body);
foreach ($emails as $email):
$mail->addTo($email);
endforeach;
var_dump($emails);
if($qid!=""):
$fullBaseUrl = getcwd();
$full_path = $fullBaseUrl . "\\pdfs\\" .$qid.".pdf";
$content = file_get_contents($full_path); // e.g. ("attachment/abc.pdf")
$attachment = new Zend_Mime_Part($content);
$attachment->type = 'application/pdf';
$attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$attachment->encoding = Zend_Mime::ENCODING_BASE64;
$attachment->filename ="quotation.pdf"; // name of file
$mail->addAttachment($attachment);
endif;
$mail->send($transport);
return true;
} catch (Zend_Exception $e) {
echo "Caught exception: " . get_class($e) . "\n";
echo "Message: " . $e->getMessage() . "\n";
exit;
// Other code to recover from the error
}
}
Please let me know where I did wrong?
Thanks in advance.
I want send email with subject using variable , this is code
public function sendmail(Request $request)
{
$data = [
'subject' => $request->input('subject'),
'name' => $request->input('name'),
'phone' => $request->input('phone'),
'email' => $request->input('email')
];
Mail::send('mail.sendmail' , $data, function($msg){
$msg->from('mygmail.com', 'Avil');
$msg->to('mygmail#gmail.com', 'Avil')->subject('Welcome to Laravel 5.1');
});
return redirect()->route('contact.index');
}
I wanna subject not "Welcome to Laravel 5.1", Subject is
public function sendmail(Request $request)
{
$data = [
'subject' => $request->input('subject'),
'name' => $request->input('name'),
'phone' => $request->input('phone'),
'email' => $request->input('email')
];
Mail::send('mail.sendmail' , $data, function($msg){
$msg->from('mygmail#gmail.com', 'Hung Nguyen');
$msg->to('mygmail#gmail.com', 'Hung Manh')->subject($data['subject']);
});
return redirect()->route('contact.index');
}
When I running display error :
Undefined variable: data
Please help me. Thank you so much
You have to pass along $data to the callback in your send method. Refer the line where Mail façade is used.
public function sendmail(Request $request)
{
$data = [
'subject' => $request->input('subject'),
'name' => $request->input('name'),
'phone' => $request->input('phone'),
'email' => $request->input('email')
];
Mail::send('mail.sendmail' , function($msg) use($data){
$msg->from('mygmail#gmail.com', 'Hung Nguyen');
$msg->to('mygmail#gmail.com', 'Hung Manh')->subject($data['subject']);
});
return redirect()->route('contact.index');
}
Im following the tutorial from symfony's website to make my phpunit's test for my controller.
Im trying to test an upload on a form and i have 3 fields on this form : title,description and file.
I use :
public function testScenarioAdd() {
$client = static::createClient();
$x_wsse = 'UsernameToken Username="username#fai.fr", PasswordDigest="aeirugbjcUbfmùJK", Nonce="OTMzOGMwYzFkYTk2MzJmYzBh", Created="2013-11-12T10:22:15+01:00"';
//X_Wsse is for the connection systeme on my application.
$image = new UploadedFile(
'/past/to/your/images.jpg',
'images.jpg',
'image/jpeg',
100000
);
$crawler = $client->request('POST', '/ad/create', array('ad_form' => array('title' => 'test', 'description' => 'Test description')),array(), array('CONTENT_TYPE' => 'application/x-www-form-urlencoded', 'HTTP_X-WSSE' => $x_wsse));
$response = $client->getResponse()->getContent();
$json_response = json_decode($response);
print_r($response);
}
When i launch it I have an error saying :
{"app_error":{"success":500,"result":[{"message":"Array to string conversion",...
Am i doing something wrong ? or missing something in my code ?
Thanks for your help :)
Edit :
Thanks but, what ive done there is working on another test without upload, i still tried it and its not working. I still have the error array to string... I think it come from the fonction UplaodedFile or maybe from my controller itself because when i try the other solution from symfony's web site with
$photo = array(
'tmp_name' => '/path/to/photo.jpg',
'name' => 'photo.jpg',
'type' => 'image/jpeg',
'size' => 123,
'error' => UPLOAD_ERR_OK
);
With putting the
$crawler = $client->request('POST', '/ad/create', array('ad_form[title]' => 'test', ad_form[description] => 'test description'),array('file' => $image),array('CONTENT_TYPE' => 'application/x-www-form-urlencoded', 'HTTP_X-WSSE' => $x_wsse));
The important part of my controller is :
if ('POST' === $request->getMethod()) {
$form->bind($request);
if ($form->isValid())
{
$Ad->preCreate();
$odm->persist($Ad);
$odm->flush();
$odm->clear();
$data = $this->listAction($request, 1, 5);
Tags::setEvent($request, $this->container, 'member.create.ad', $user->getId(), $Ad->getId());
return $data;
} else {
$data = Errors::formatJson($form, $this->container);
}
}
}
return new JsonResponse(array('ad_create' => $data));
Im kinda new in symfony, i really dont know where this error can come from...
Client::Request method expects you to provide it with one-dimensional array of data. So try this code:
<?php
//...
$crawler = $client->request('POST', '/ad/create',
array('ad_form[title]' => 'test',
'ad_form[description]' => 'Test description'),
array(),
array('CONTENT_TYPE' => 'application/x-www-form-urlencoded', 'HTTP_X-WSSE' => $x_wsse));
Hey guys trying to declare a variable in CakePHP in the Fields Controller. This variable will display the template id from the template table, but the view is saying the variable is undefined even though we delared it in the controller. Temaplates has many fields and fields belongs to templates.
Here is the Fields Controller:
<?php
class FieldsController extends AppController{
public $uses = array('Template');
function add(){
$this->set('title_for_layout', 'Please Enter Your Invoice Headings');
$this->set('stylesheet_used', 'style');
$this->set('image_used', 'eBOXLogo.jpg');
$this->Session->setFlash("Please create your required fields.");
$templates = $this->Template->find('list');
//$current_template = $this->request->data['Field']['template_id'];
// right way to do it, but Template is undefined, and says undefined var
//$template = $this->request->data['Field']['template_id'];
// makes sense with the find, no errors, but still doesnt print in form, says undefined var
//$current_template = $this->request->data($template['Field']['template_id']);
if($this->request->is('post'))
{
$this->Field->create();
if ($this->Field->save($this->request->data))
{
if($this->request->data['submit'] == "type_1")
{
$this->Session->setFlash('The field has been saved');
$this->redirect( array('controller' => 'fields','action' => 'add'));
}
if($this->request->data['submit'] == "type_2")
{
$this->Session->setFlash('The template has been saved');
$this->redirect( array('controller' => 'templates','action' => 'index'));
}
}
else
{
$this->Session->setFlash('The field could not be saved. Please, try again.');
}
}
}
}
And here is our add view which adds fields:
<?php
echo $this->Form->create('Field', array('action'=>'add'));
echo $this->Form->create('Field', array('action'=>'add'));
echo $this->Form->input('name', array('label'=>'Name: '));
echo $this->Form->input('description', array('label'=>'Description: '));
//echo $this->Form->input('template_id',array('label'=>'Template ID: ', 'type' => 'select', 'options' => $templates));
echo $this->Form->input('template_id',array('label'=>'Template ID: ', 'type' => 'text', 'default'=> $templates));
//echo $this->Form->input('templates_id', array('label'=>'Template ID: ', 'type' => 'text', 'default' => $current_template['templates_id']));//this would be the conventional fk fieldname
echo $this->Form->button('Continue adding fields', array('name' => 'submit', 'value' => 'type_1'));
echo $this->Form->button('Finish adding fields', array('name' => 'submit', 'value' => 'type_2'));
echo $this->Form->end();
?>
You should try the following code:
<?php
class FieldsController extends AppController{
public $uses = array('Template', 'Field');
function add(){
$this->set('title_for_layout', 'Please Enter Your Invoice Headings');
$this->set('stylesheet_used', 'style');
$this->set('image_used', 'eBOXLogo.jpg');
$this->Session->setFlash("Please create your required fields.");
$templates = $this->Template->find('list', array('fields' => array('Template.id, Template.template_name' );
$this->set('templates', $templates);
//$current_template = $this->request->data['Field']['template_id'];
// right way to do it, but Template is undefined, and says undefined var
//comment: You should check the request data with in if condition
//$template = $this->request->data['Field']['template_id'];
// makes sense with the find, no errors, but still doesnt print in form, says undefined var
//$current_template = $this->request->data($template['Field']['template_id']);
if($this->request->is('post'))
{
$this->Field->create();
if ($this->Field->save($this->request->data))
{
if($this->request->data['submit'] == "type_1")
{
$this->Session->setFlash('The field has been saved');
$this->redirect( array('controller' => 'fields','action' => 'add'));
}
if($this->request->data['submit'] == "type_2")
{
$this->Session->setFlash('The template has been saved');
$this->redirect( array('controller' => 'templates','action' => 'index'));
}
}
else
{
$this->Session->setFlash('The field could not be saved. Please, try again.');
}
}
}
}
You view should looks like:
<?php
echo $this->Form->create('Field', array('action'=>'add'));
echo $this->Form->input('name', array('label'=>'Name: '));
echo $this->Form->input('description', array('label'=>'Description: '));
echo $this->Form->input('template_id',array('label'=>'Template ID: ', 'options' => $templates));
//echo $this->Form->input('template_id',array('label'=>'Template ID: ', 'type' => 'text', 'default'=> $templates));
//echo $this->Form->input('templates_id', array('label'=>'Template ID: ', 'type' => 'text', 'default' => $current_template['templates_id']));//this would be the conventional fk fieldname
echo $this->Form->button('Continue adding fields', array('name' => 'submit', 'value' => 'type_1'));
echo $this->Form->button('Finish adding fields', array('name' => 'submit', 'value' => 'type_2'));
echo $this->Form->end();
?>
Kindly check and verify if it is working for you or not.
You are missing $this->set('templates', $templates); after doing the find() for templates in your controller.