Hi all,
any idea why this error appears while sending mails with the contact form demo code?
thx for help.
Hi all,
any idea why this error appears while sending mails with the contact form demo code?
thx for help.
Check this: https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#could-not-instantiate-mail-function
works! thanks alot!
I also have this damn error message âCould not instantiate mail function.â. Form ist hosted with Host Europe and they need this parameter â-f mail@mydomain.deâ. Adding it does not help and now I wonder, if I might add it at the wrong position?
I added it to the controller of the contact form. Oh ⊠btw, I am using the mail contact form in the Cookbook.
$kirby->email([
'template' => 'email',
'from' => 'mail@mydomain.com',
'replyTo' => $data['contactform-email'],
'to' => 'mail@mydomain.com',
'subject' => esc($data['contactform-name']) . ' hat eine Nachricht ĂŒber die Website gesendet',
'data' => [
'text' => esc($data['contactform-text']),
'sender' => esc($data['contactform-name']),
'-f admin@domain.de'
]
]);
I also made sure that the standard email address needed by Host Europe also is set in their KIS. Any hint?
Thanks in advance and have a lovely day,
/marc
Hmm ⊠I just read, that I actually donât need the -f parameter, if I added a standard email:
Es ist möglich ohne den Parameter â-fâ E-Mails aus Skripten zu versenden. Dazu ist es nötig eine Standard-E-Mail-Adresse im KIS einzurichten.
Strange. Why the heck to I get this error then?
Hey Marc! Is there anything in the PHP error logs or server error logs?
Hey. I just activated loggin errors. He did not have them turned on. I need to wait 15 minutes and try again to see if an error is recorded.
Hmm somehow it does not log anything. Neither on the website â as I set it to âLogging Outputâ to see if I get more info on the website. No chance to see any other info sadly.
Hm, is sendmail enabled or are you sending mail via smtp transport?
Sendmail should be enabled. At least I used it with the form I built for the K2 version of this site. I thought, I do the shortcut and use the pre-built form, but I guess, I was wrong
Is there any other pre-built contact form around? Otherwise, I simply look into building my own again, as I have no idea why this is not sending.
OK. I found some more time today to check this and just wanted to notify you that it was a problem â as expected â with Host Europe and their way of dealing with stuff like this. All things (like their âStandard Email Addressâ and/or the -f parameter) were correctly set. But what my mistake was and what I did not know is, that you need to use an email address in the âfromâ field that is part of the web package you use the script in. You canât use any email where the URL is not part of the package you run this script in. Even though you own the domain and run it on the same KIS or Server, it needs to be part of the Domain(s) you use in this package. This is strict, but makes sense in a way.
So now it is working perfectly.
Hi all! I would like to reopen this, as I have the same problem, too, and I am absolutely unable to solve it after struggling 2 days
I am testing the site on a subdomain (without ssl encryption), might that be a problem? Does anyone have a hint about how to eventually debug this error more specifically, to get a clue about what is
wrong?
php info says
sendmail_path /usr/sbin/sendmail -finfo@domain.de -t -i
SMTP localhost
smtp_port 25
if that could help.
I did not change anything within the config.php file, so I guess SMTP is not configured within kirby and I am trying to send a mail from and to info@domain.de. Anyhow, I tested the same system on another server and it worked! I am getting crazy âŠ
The site is hostet at df.eu, by the way, maybe anyone experienced a similiar error with that hoster? A million thanks in advance!
If you call the mail()
function manually in a template/controller, like so
mail ('info@domain.de', 'Test', 'works!', '', '-f info@domain.de');
does this work?
I have tried this, and this works:
<?php
$to = "info@domain.de";
$subject = "This is subject";
$message = "<b>This is HTML message.</b>";
$message .= "<h1>This is headline.</h1>";
$header = "From:info@domain.de \r\n";
$header .= "Cc:info@domain.de \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true ) {
echo "Message sent successfully...";
}else {
echo "Message could not be sent...";
}
?>
Hi all!
It seems, that at least the error cause is found: after talking to the df.eu support, the reason seems to be, that Domainfactory changed their general server configuration and now they are forcing a ReturnPath with the parameter -f within the sendmail_path in the php.ini (which I cannot access). Kirby seems to force a ReturnPatch with phpmailer by itsÂŽ own, which causes an error. The suggested solution should be to add the parameter 0 to phpmailer.
$mail->setFrom('absender@domain.tld', 'Mailer' ,0);
But I absolutely do not know where to integrate that in the system and I found no documentation. Alternatively, I tried to integrate this within my script of the control contact.php, but it does not work:
$kirby->email([
'beforeSend' => function ($mailer) {
$mailer->setFrom('info@domain.de', esc($data['name']) ,0);
return $mailer;
}
]);
I am not sure, where to integrate that correctly, here is my complete code, whichs throws the error " Undefined variable: data". I think after 2 days staring at this piece of code, I am getting blind, a coffe and a cake for the one who solves this:
<?php
return function($kirby, $pages, $page) {
$alert = null;
if($kirby->request()->is('POST') && get('submit')) {
// check the honeypot
if(empty(get('website')) === false) {
go($page->url());
exit;
}
$data = [
'name' => get('name'),
'email' => get('email'),
'text' => get('text'),
'optin' => get('optin')
];
$rules = [
'name' => ['required', 'minLength' => 1],
'email' => ['required', 'email'],
'text' => ['required', 'minLength' => 1, 'maxLength' => 3000],
'optin' => array('required')
];
$messages = [
'name' => 'Please enter a valid name',
'email' => 'Please enter a valid email address',
'text' => 'Please enter a text between 3 and 3000 characters',
'optin' => 'Bitte markieren Sie die Checkbox, um uns zu erlauben Sie zu kontaktieren.'
];
// some of the data is invalid
if($invalid = invalid($data, $rules, $messages)) {
$alert = $invalid;
// the data is fine, let's send the email
} else {
try {
$kirby->email([
'beforeSend' => function ($mailer) {
$mailer->setFrom('info@domain.de', esc($data['name']) ,0);
return $mailer;
},
'template' => 'email',
'from' => 'info@domain.de',
'replyTo' => $data['email'],
'to' => 'info@domain.de',
'subject' => esc($data['name']) . ' hat Ihnen eine Nachricht ĂŒber Ihr Kontaktformular geschickt',
'data' => [
'text' => esc($data['text']),
'sender' => esc($data['name']),
'email' => esc($data['email'])
]
]);
} catch (Exception $error) {
if(option('debug')):
$alert['error'] = 'Ihre Nachricht konnte leider nicht verschickt werden <strong>' . $error->getMessage() . '</strong>';
else:
$alert['error'] = 'Da ist leider etwas schiefgelaufen!';
endif;
}
// no exception occurred, let's send a success message
if (empty($alert) === true) {
$success = 'Ihre Nachricht wurde erfolgreich versandt! Wir melden uns so schnell wie möglich bei Ihnen.';
$data = [];
}
}
}
return [
'alert' => $alert,
'data' => $data ?? false,
'success' => $success ?? false
];
};
Thanks a million!!
When using a variable defined outside the scope of the closure, you have to pass it via a use
statement:
$kirby->email([
'beforeSend' => function ($mailer) use($data) {
$mailer->setFrom('info@domain.de', esc($data['name']) ,0);
return $mailer;
}
]);
Thank you for that hint! But with that it throws the âCould not instantiate mail function.â again.
Do you know another way to keep phpmailer from forcing the ReturnPath like
$mail->setFrom('info@domain.de', 'Mailer' ,0);
or do you have an idea, why the code above does not work?
Thank you so much!
Hi there! I have solved the problem in the meantime and just wanted to let you know, in case anyone is experiencing similar issues. The following code uses the direct access to the phpmailer function within Kirby to let the server define the ReturnPath instead of phpmailer, by removing the âSenderâ value:
'beforeSend' => function ($mailer) {
$mailer->Sender = '';
return $mailer;
}
Cheers and thank you for participating!
Thanks for posting this! This just saved me : )