Contact form un Ghost without 3rd party services

Hi all!

I’m running a self hosted Ghost personal blog, and I’m setting up some features to interact with the visitors.

What I want is a contact form page so visitors can send me an email. I’ve already see many posts explaining how to configure forms, but they’re using 3rd party services such as Formspree, Getform, Mailgun, etc, and what I want is a contact form using SMTP transport to send the emails to my mailbox.

Using PHP I know how to do that, but honestly I do not have many knowledge on NodeJS to do that.

Is there any way to create our own form using SMTP authentication in Ghost?

Best Regards,
Diogo

You can create your contact form script using php and have the html form you’ve added to your Ghost site submit to your php script that you’re hosting on your server. There’s no requirement to use node.js.

Thank you Kevin!

And how can I run php script in Ghost? For example if I create an HTML file in theme root folder, I can access it from browser, but if I create a php script in the same location it will download the file instead of open it.

I’ve already tried to setup the nginx config to run php files with the php-fpm socket but with no success. Could you help me on that?

Best Regards,
Diogo

And how can I run php script in Ghost?

You don’t, this would be outside of Ghost, most likely served by the web server that sits in front of Ghost as a proxy.

Sounds like you’re heading in the right direction. In the server block for your Ghost site you’ll want an additional location directive for your php files, eg:

location /php/ {
     root /var/www/php/

     ... fastcgi setup ...
}

Hi Kevin,

Thanks! I’ve figured out this by took some kind of advantage of ./system/nginx-root path that ghosts adds to the Nginx server block.

Then, here, I’ve inserted the PHP code and my form page is able to call the PHP script to send the authenticated email.