Chyba pri odosielaní emailu TypeError key() expects parameter 1 to be array, null given
- KristianSubweb
- Člen | 146
Ahojte mám chybu v odoslaní emailu pomocov Nette\Mail\SmtpMailer prosím nevšímajte si to riešenie :D
TypeError key() expects parameter 1 to be array, null given
public function send(Form $form) {
$data = $form->getHttpData();
$message = new Message;
$html = "<h2>Nová správa z vašej stránky / moautoservis.sk</h2>";
$html = $html . "<p>Name: ".$data['name']."</p>";
$html = $html . "<p>E-mail: ".$data['email']."</p>";
$html = $html . "<p>Text: ".$data['message']."</p>";
$message->setHtmlBody($html);
$message->setSubject("Kontaktný formulár - www.welland.sk");
$message->addTo("email@gmail.com");
$this->flashMessage("Ďakujeme za vašu správu.");
$mailer = new SmtpMailer([
"host" => "smtp.****.sk",
"port" => 465,
"username" => "***@email.com",
"password" => "****",
"secure" => "ssl"
]);
$mailer->send($message);
//$this->redirect("this");
}
Ďakujem :)
Editoval KristianSubweb (24. 4. 2018 19:46)
- KristianSubweb
- Člen | 146
David Grudl napsal(a):
Pošli sem celou Tracy
TypeError
key() expects parameter 1 to be array, null given search►
Source file
Call stack
.../vendor/nette/mail/src/Mail/SmtpMailer.php:97 source key(arguments)
.../web-project/app/presenters/HomepagePresenter.php:71 source Nette\Mail\SmtpMailer->send(arguments)
61: $this->flashMessage("Ďakujeme za vašu správu.");
62:
63: $mailer = new SmtpMailer([
64: "host" => "smtp.websupport.sk",
65: "port" => 465,
66: "username" => "mailer@moautoservis.sk",
67: "password" => "autoservismo421",
68: "secure" => "ssl"
69: ]);
70:
71: $mailer->send($message); //tento riadok označuje
72:
73: //$this->redirect("this");
74:
75:
- jAkErCZ
- Člen | 322
rkor napsal(a):
Nechybí ti tam?
$message->setFrom()
To je asi ono..
Zkusil bych to asi nějak takto:
try {
$data = $form->getHttpData();
$message = new Message;
$html = "<h2>Nová správa z vašej stránky / moautoservis.sk</h2>";
$html = $html . "<p>Name: ".$data['name']."</p>";
$html = $html . "<p>E-mail: ".$data['email']."</p>";
$html = $html . "<p>Text: ".$data['message']."</p>";
$message->setFrom("email@gmail.com")
->setSubject("Kontaktný formulár - www.welland.sk")
->setHtmlBody($html);
$this->flashMessage("Ďakujeme za vašu správu.");
$mailer = new SmtpMailer([
"host" => "smtp.****.sk",
"port" => 465,
"username" => "***@email.com",
"password" => "****",
"secure" => "ssl"
]);
$mailer->send($message);
//$this->redirect("this");
} catch (InvalidStateException $ex) {
$this->flashMessage('Chyba!!');
}
Editoval jAkErCZ (24. 4. 2018 21:14)
- KristianSubweb
- Člen | 146
jAkErCZ napsal(a):
rkor napsal(a):
Nechybí ti tam?
$message->setFrom()
To je asi ono..
Zkusil bych to asi nějak takto:
try { $data = $form->getHttpData(); $message = new Message; $html = "<h2>Nová správa z vašej stránky / moautoservis.sk</h2>"; $html = $html . "<p>Name: ".$data['name']."</p>"; $html = $html . "<p>E-mail: ".$data['email']."</p>"; $html = $html . "<p>Text: ".$data['message']."</p>"; $message->setFrom("email@gmail.com") ->setSubject("Kontaktný formulár - www.welland.sk") ->setHtmlBody($html); $this->flashMessage("Ďakujeme za vašu správu."); $mailer = new SmtpMailer([ "host" => "smtp.****.sk", "port" => 465, "username" => "***@email.com", "password" => "****", "secure" => "ssl" ]); $mailer->send($message); //$this->redirect("this"); } catch (InvalidStateException $ex) { $this->flashMessage('Chyba!!'); }
No už to nevyhadzuje to ale teraz prezmenu toto:
SMTP server did not accept DATA with error: 554 5.5.1 Error: no valid
recipients
public function send(Form $form) {
try {
$data = $form->getHttpData();
$message = new Message;
$html = "<h2>Nová správa z vašej stránky / moautoservis.sk</h2>";
$html = $html . "<p>Name: ".$data['name']."</p>";
$html = $html . "<p>E-mail: ".$data['email']."</p>";
$html = $html . "<p>Text: ".$data['message']."</p>";
$message->setFrom("email@email.com")
->setSubject("Kontaktný formulár - www.welland.sk")
->setHtmlBody($html);
$this->flashMessage("Ďakujeme za vašu správu.");
$mailer = new SmtpMailer([
"host" => "smtp.****.sk",
"port" => 465,
"username" => "email@email.sk",
"password" => "****",
"secure" => "ssl"
]);
$mailer->send($message);
$this->redirect("this");
} catch (InvalidStateException $ex) {
$this->flashMessage('Chyba!!');
}
}