getgrav / grav-plugin-email

Grav Email Plugin
http://getgrav.org
MIT License
37 stars 29 forks source link

Can't send email via PHP Mail #67

Closed non25 closed 7 years ago

non25 commented 7 years ago

Hi dear devs. I've been enjoying grav so much for the past few days, its amazing. Thanks a lot. But then I tried to configure form emails... Can't get it to send something via PHP Mail and that's my preferable way to do it.

I found out that I could debug using debug: true in email.yaml. But I haven't found any info on how do I debug. Only that I should use smpt instead of 'unreliable' PHP Mail, which works everytime I tested on the same hosting with the following simple code...

<?php
    error_reporting(0);
    if (isset($_POST["submit"])) {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $human = intval($_POST['human']);
        $from = $email;
        $to = 'email_to_send@domain.com';
        $subject = 'It was sent from domain.com';

        $body ="From: $name\n E-Mail: $email\n Message:\n $message";
        // Check if name has been entered
        if (!$_POST['name']) {
            $errName = 'Enter your name';
        }

        // Check if email has been entered and is valid
        if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
            $errEmail = 'Enter correct email';
        }

        //Check if message has been entered
        if (!$_POST['message']) {
            $errMessage = 'Enter message';
        }
        //Check if simple anti-bot test is correct
        if ($human !== 14) {
            $errHuman = 'The correct answer is: 14';
        }
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
    if (mail ($to, $subject, $body, $from)) {
        $result='<div class="alert alert-success">Ty. Will reach to you soon.</div>';
    } else {
        $result='<div class="alert alert-danger">Sorry, there\'s some kind of mistake. Try to reach email_to_send@domain.com directly.</div>';
    }
}
    }
?>

All I have found about email logs was quite unhelpful logs/grav.log, which got something like this:

[2017-10-26 13:04:49] grav.DEBUG: Email Log:  [] []

Here's my form config. form.txt Sending from it saves contents to user/data/contact-form as expected.

Here's my email.yaml.

enabled: true
from:
from_name:
to: myemail@myemail.com
to_name: Any Name
mailer:
  engine: mail
  smtp:
    server: localhost
    port: 25
    encryption: none
    user: ''
    password: ''
  sendmail:
    bin: '/usr/sbin/sendmail'
content_type: text/html
debug: false

Can you help me not to reinvent the wheel and making simpler version of your plugin? :(

rhukster commented 7 years ago

It seems Swift has deprecated mail transport engine and it didn't work anyway in the last few versions of Swift: https://github.com/swiftmailer/swiftmailer/issues/866

I've set the default to sendmail, but really you should use SMTP for maximum reliability. I've updated the docs and also made the debug more robust and it should log out to logs/email.log if you have debug enabled when sending.