I have got simple contact form with custom fields which is used for contact purpose. How can i set up this form to send copy of the message to sender ?
Any help is appreciated.
There is no such configuration option in magento.
You may create custom module in local namespace, where you override controller class Mage_Contacts_IndexController and change the code of postAction() method to add addBcc() method inside. Like this:
$mailTemplate->setDesignConfig(array('area' => 'frontend'))
->setReplyTo($post['email'])
->addBcc($post['email'])
->sendTransactional(
Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
null,
array('data' => $postObject)
);
Related
I want to store the email body in my communications table. My controller:
Mail::to($user->email)->send(new WelcomeEmail($subscription));
Communication::create([
'to' => $user->email,
'subject' => 'Welcome Email',
'body' => '???'
]);
My email goes out (successfully) and I am able to create a Communication record, but have no idea how to retrieve the email body.
After reading the Mail manual, I thought I could work with an event:
protected $listen = [
'Illuminate\Mail\Events\MessageSending' => [
'App\Listeners\LogSentMessage',
],
];
But here I get only the full plain text email. If I create an instance of the mail, with:
$email = Mail::to($user->email)->send(new WelcomeEmail($subscription));
the outcome of dd($email); is null.
Some extra info, in my WelcomeEmail.php, I am using a view:
public function build()
{
return $this->view('emails.welcome_email');
}
You can directly do this to render Mailable and store it in a variable
$html = (new WelcomeEmail($subscription))->render();
I found a solution, hopefully it can help other people.
$body = View::make('emails.welcome_email')
->with('subscription', $this->subscription)
->with('template', $this->template)
->render();
I rendered the view and saved it in the body variable.
Inside my extbase extension I have an appointment model and users can write feedback to how the appointment was.
So I created a feedback model with different fields.
Now what should I implement for when the user clicks on the "Create Feedback" button?
So far I got this, but it's not working:
<f:link.action action="edit" controller="Feedback" arguments="{appointment:appointment}">
I get the the error:
Argument 1 passed to
...Controller\FeedbackController::newAction() must be an instance of
...\Model\Appointment, none given
FeedbackController:
/**
* action new
* #param ...\Domain\Model\Appointment $appointment
* #return void
*/
public function newAction(...\Domain\Model\Appointment $appointment) {
$this->view->assign('appointment', $appointment);
}
Why do I get this error? (the appointment object was definitely there, I debugged it)
I figure it must've something to do with the switch from AppointmentController to FeedbackController.
What's the best way to implement this?
You need the pluginName parameter in your link generation if you use different plugins.
<f:link.action action="edit" controller="Feedback" pluginName="your_plugin" arguments="{appointment:appointment}">
When generating a link TYPO3 prepends the "namespace" of the argument to the link like this: tx_myplugin[action]=new. Make sure, that the pluginName is the same one you defined in ext_localconf.php. In this case the pluginName would be your_plugin.
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Vendor.' . $_EXTKEY,
'your_plugin',
array(
'Feedback' => 'new',
),
// non-cacheable actions
array(
'Feedback' => '',
)
);
Check the plugin-controller-action array in your ext_localconf.php and post it. Maybe there is something wrong.
If you get this error :
Argument 1 passed to ...Controller\FeedbackController::newAction()
must be an instance of ...\Model\Appointment, none given
it's because you give the controler a NULL object and taht's not allowed with your controller.
To avoid this error, you could allow NULL object in your controller :
/**
* action new
* #param ...\Domain\Model\Appointment $appointment
* #return void
*/
public function newAction(...\Domain\Model\Appointment $appointment=NULL) {
$this->view->assign('appointment', $appointment);
}
this is weird because in your link, you call an action 'edit' and you have an error in 'newAction' controller instead of 'editAction' controller, you should have the 'edit' action allowed for your plugin (cachable or not) :
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Vendor.' . $_EXTKEY,
'your_plugin',
array(
'Feedback' => 'edit',
),
// non-cacheable actions
array(
'Feedback' => 'edit',
)
);
and as Natalia wrote add the plugin name if the action you want to call belongs to another plugin.
<f:link.action action="edit" controller="Feedback" pluginName="your_plugin" arguments="{appointment:appointment}">
Florian
I want to embed a contact form in multiple places on my website.
I developed a contact form in a contact() function within my MessagesController.php:
// MessagesController.php
public function contact()
{
$this->set('title', 'Contact');
$message = $this->Messages->newEntity();
... // shortened for brevity
$this->set(compact('message'));
$this->set('_serialize', ['message']);
}
I loaded the CSRF component in the initialize() function of the AppController.php:
// AppController.php
public function initialize()
{
parent::initialize();
$this->loadComponent('Csrf');
... // shortened for brevity
}
The form is rendered with a contact.ctp and it works fine.
I followed CakePHP's cookbook which suggests using requestAction() within an element, then echoing the element where I want it:
// contact_form.ctp
<?php
echo $this->requestAction(
['controller' => 'Messages', 'action' => 'contact']
);
?>
And:
// home.ctp
<?= $this->element('contact_form'); ?>
The problem is that the form is rendered fine, but the CSRF hidden field is missing. It should be automatically added to the form since the CSRF component is called in the AppController.php.
I guess either using an element with a requestAction() isn't the solution for this particular case, or I am doing something wrong.
Any ideas? Thanks in advance for the input!
Request parameters need to be passed manually
requestAction() uses a new \Cake\Network\Request instance, and it doesn't pass the _Token and _csrf parameters to it, so that's why things break.
While you could pass them yourself via the $extra argument, like
$this->requestAction(
['controller' => 'Messages', 'action' => 'contact'],
[
'_Token' => $this->request->param('_Token'),
'_csrf' => $this->request->param('_csrf')
]
);
Use a cell instead
I would suggest using a cell instead, which is way more lightweight than requesting an action, also it operates in the current request and thus will work with the CSRF component out of the box.
You'd pretty much just need to copy your controller action code (as far as the code is concerned that you are showing), and add a loadModel() call to load the Messages table, something like
src/View/Cell/ContactFormCell.php
namespace App\View\Cell;
use Cake\View\Cell;
class ContactFormCell extends Cell
{
public function display()
{
$this->loadModel('Messages');
$this->set('title', 'Contact');
$message = $this->Messages->newEntity();
// ... shortened for brevity
$this->set(compact('message'));
$this->set('_serialize', ['message']);
}
}
Create the form in the corresponding cell template
src/Template/Cell/ContactForm/display.ctp
<?php
echo $this->Form->create(
/* ... */,
// The URL needs to be set explicitly, as the form is being
// created in the context of the current request
['url' => ['controller' => 'Messages', 'action' => 'contact']]
);
// ...
And then wherever you want to place the form, just use <?= $this->cell('ContactForm') ?>.
See also
API > \Cake\Routing\RequestActionTrait::requestAction()
Cookbook > Views > Cells
I want to send emails to my users after they get registered in my site. Its like an account-activation mail. I have tried this, but its not working(its my own function from where I am trying to send mails) :
public function send_mail($from,$to,$subject,$msg,$value,$template){
$Email=new CakeEmail('smtp');
$Email->template('template','default')
->viewVars(array('value'=>$value))
->emailFormat('html')
->to($to)
->subject($subject)
->from(array($from=>'My Site'))
->send();
}
This is my email.php file's code :
<?php
class EmailConfig{
public $smtp=array(
'transport'=>'Smtp',
'from'=>array('notification#domain.com'=>'My Site'),
'host'=>HOST,
'port'=>PORT,
'timeout'=>30,
'username'=>'notification#domain.com',
'password'=>PASSWORD,
'client'=>null,
'log'=>false,
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
}
Please help me. Is there anything wrong in my code, or, I have to do something else ?
Thanks.
I don't know if you replaced it with dummy data for security's sake, but all those fields in email.php need to contain valid information for an SMTP server. It won't ever work with blatantly false information like "notification#domain.com" as a username.
Not trying to be snarky; just not clear if you understood the default values need to be changed.
By default you have the following URL-syntax in ZF: /module/controller/action. What i want, is to build an menu-system where i can use any URL I want.
Lets say I make an menu-item called 'news'. When i call http://www.site.com/news i want to have the folowing loaded:
module: news
controller: frontpage
action: display
These config-values must be configured in the database-record for the menu-item.
How can I do this in zend? I spend a lot of time searching for it, but I still can't figure out how to. Does anybody?
I'd suggest using a front controller plugin to scan your database for all the entries, create routing rules based on those entries and add them to the router (see this).
Of course caching strategy is recommended so that you don't do a lot of processing on every request.
You can create a plugin and in routeStartup define something that intercept your request and route /module/controller/action to /action, but for this all your action names must be unique :
class My_CustomRouterPlugin extends Zend_Controller_Plugin_Abstract
{
public function routeStartup(Zend_Controller_Request_Abstract $request)
{
$fc = Zend_Controller_Front::getInstance();
$action =$fc->getRequest()->getActionName();
$router = $fc->getRouter();
$model= new myModel();
$myPage = $model->getPageByAction($action);
$route = new Zend_Controller_Router_Route('/action', array(
'module' => $myPage->getModule();
'controller' => $myPage->getController();
'action' => $action;
));
$router->addRoute($action, $route);
return $router;
}
}
In myModel define a method can get you an object(or an array) that contains module, controller names (from you DB ).
and register this plugin in your bootstrap:
$front->registerPlugin(new My_CustomRouterPlugin());