Mail is not working in kirby

               $email = email(array( 'to' => 'd*********143@gmail.com',
                                     'from'    => 'd*********143@gmail.com',
                                      'subject' => 'Sending emails with Kirby is easy',
                                      'body'    => 'Hey! This was really easy!'
                                    )); 
                                  if($email->send()) {
                                  echo 'The email has been sent';
                                  } else { 
                                  echo $email->error()->message();
                                 }

this mail function is not working in kirby
do i need to define something of email();

Hello @Dhamu143
"is not working" is not going to help us a lot here. Can you give more specifics?

  1. Have you turned debugging on?
  2. What error are you getting?
  3. What server are you testing on?

error message is “The email could not be sent”. i am testing this on apache .
do i need to configure something on server side?

Are you testing this on your local machine using XAMP, WAMP or something similar ?

yes i am on ubuntu os.and using LAMP

Sending emails from the localhost is not easy. You need to setup the mailer on your machine. This is not something that you would need to do on a normal server as it comes installed almost systematically.
There have been other posts on the forum about trying to install it on local machines and it seems like it’s a bit hard to do.

then I host my website then it will work or not ?

You’ll have to test it on your remote server.

i have installed postfix for sending mail from localhost . now i am getting message that email has been sent but in my mail i have not received any mail. not even in spam.

Have you enabled sendmail in your php.ini as well? You might want to check this post as well: Contact form easy solution

here is my php.ini file

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path =
sendmail_path =/usr/sbin/sendmail -t -i -f  dharmeshkashyap@jacksolutions.biz

please check if is there any mistake here.

email() function will furn automatically or for that i need to define something.?

The Kirby email() function works with the PHP mail() function by default. You don’t need to configure anything to use it (besides the php.ini settings).

However the PHP mail() function unfortunately is very hard to debug, it doesn’t return a detailed error message.
If you don’t get an error message with your php.ini configuration, that means that the email has been accepted by sendmail. However it does not mean that the email could be delivered to your recipient’s mailbox. Some email providers straight up block emails from home networks because of spam. So it will probably work on a real web server out of the box.

but from my above code , initially i was getting that email could not sent. then i install postfix and now i am getting that email has been sent. but email is not deliver to any account. :frowning:

can you help to find out where is the mistake or is there any alternative way?

As Lukas wrote above:

So in fact the email is in fact not delivered to your inbox although it was sent. You could try with another email account, though.

As I wrote above: Because you don’t get an error anymore, that means that your setup is probably correct. However some email providers block email from home networks. Only way to test your code reliably is on a “real” server.

Cha i am having opposite problem. I get error “The email could not be sent.” but the email is sent :smiley:

How about that? god i hate email