Temat: Cannot modify header information
witam,
mam problem ze sławnym komunikatem: Cannot modify header information.
Problem pojawia się w momencie gdy chcę wysłać maila za pomocą SwiftMailer - problem o tyle ciekawy, że w jednym projekcie działa, a w drugim nie ![]()
Warning (2): Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\aplikacja\app\controllers\components\swift_mailer.php:1) [CORE\cake\libs\controller\controller.php, line 640]
Code | Context
$status = "Location: http://localhost/fagp/pages/form_ok"
header - [internal], line ??
Controller::header() - CORE\cake\libs\controller\controller.php, line 640
Controller::redirect() - CORE\cake\libs\controller\controller.php, line 621
ContactsController::add() - APP\controllers\contacts_controller.php, line 35
Object::dispatchMethod() - CORE\cake\libs\object.php, line 115
Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 227
Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 194
[main] - APP\webroot\index.php, line 88pierwsze linie kodu swiftmailer komponent to
<?php
// File -> app/controllers/components/swift_mailer.php
//http://bakery.cakephp.org/articles/view/updated-swiftmailer-4-xx-component-with-attachments-and-plugins
/**
* SwiftMailer 4.03 Component
*
* @author Matt Huggins
* @version 2.21
* @license MIT
* @category Components
* @modifiedby d3f_l3pp4rd
*/wiec nie ma nic co moze powodowac blad.
Korzystam z SwiftMailer w nastepujacy sposob
function add() {
if (!empty($this->data)) {
$this->Contact->create();
if ($this->Contact->save($this->data)) {
$this->Session->setFlash(__('The Contact has been saved', true));
$this->contact($this->data);
$this->redirect(array('controller'=>'pages','action'=>'form_ok'));
}
else {
$this->Session->setFlash(__('The Contact could not be saved. Please, try again.', true));
}
}
}funkcja $this->contact();
$this->SwiftMailer->smtpHost = 'tutaj jest host;
// $this->SwiftMailer->smtpPort = 465;
$this->SwiftMailer->smtpUsername = 'login';
$this->SwiftMailer->smtpPassword = 'haslo';
$this->SwiftMailer->sendAs = 'html';
$this->SwiftMailer->from = 'adres_email_smtpl';
$this->SwiftMailer->fromName = 'Automat';
$this->SwiftMailer->to = 'tutaj to wysylaml';
$this->set('message', $data);
try {
if(!$this->SwiftMailer->send('kontakt', 'Kontakt ze strony xxx')) {
foreach($this->SwiftMailer->postErrors as $failed_send_to) {
$this->log("Failed to send email to: $failed_send_to");
}
}
}
catch(Exception $e) {
$this->log("Failed to send email: ".$e->getMessage());
}
$this->autoRender = false;
} szablon wiadomości kontakt.ctp wyglada tak
<p><?php __('Name'); ?>: <?php echo $message['Contact']['name'] ?></p>
<p><?php __('Email'); ?>: <?php echo $html->link($message['Contact']['email'],'mailto:'.$message['Contact']['email']) ?></p>
<p><?php __('Subject'); ?>: <?php echo $message['Contact']['subject'] ?></p>
<p><?php __('Message'); ?>: <?php echo $message['Contact']['message'] ?></p>oczywiście sprawdziłem i nigdzie nie ma zadnych znaków po "?>"
ma ktoś może pomysł gdzie leży przyczyna?