phpwidgetmuse

adobe muse form not sending emails


I am using a contact form widget on my muse created website. The emails are not being sent and I keet getting the following error message:

"Form PHP script is missing from web server, or PHP is not configured correctly on your web hosting provider. Check if the form PHP script has been uploaded correctly, then contact your hosting provider about PHP configuration"

I am also responsible for the server and using an AWS EC2 instance (Amazon Linux AMI).

When I ran the form_check.php script I got green checkmarks on the first two of the following three checks. The third check was a Red Cross.

PHP version ok

Mail configuration: No known problems detected with php mail configuration.

Spam control: Form may send email successfully, but limiting spam submissions by IP address will not work.

Not sure if this is the issue or something else.

Edit#1

Okay, so the reason the third check item was not green was that MYSQL was not installed on the server. After installing MYSQL all three are checked green however the email is still not sending.


Solution

  • I got it to work by using PHPMailer.

    Firstly go to https://github.com/PHPMailer/PHPMailer and get the dependency. I just downloaded the zip and installed the PHPMailer-master Directory in my /var/www/html folder.

    The only other thing that is necessary is to modify the form_process.php file.

    In that file I did two things. The first is to add the require statement for PHPMailer which is shown on the PHPMailer page linked above. It is important that you do this at the top and not in any functions:

    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    
    require '../PHPMailer-master/src/Exception.php';
    require '../PHPMailer-master/src/PHPMailer.php';
    require '../PHPMailer-master/src/SMTP.php';
    

    The next was to change the following function. This assumes the username and password stored in an ini file called access.ini which is in the /var/www folder. Of course you can use whatever way you like to obfuscate your secrets. I left in the commented out lines on purpose for those that may need extra functionality. Just don't uncomment the $mail->SMTPDebug = 2;

    function email_form_submission($form) {
    
        $configuration = parse_ini_file('../../access.ini');
    
        $emailPassword = trim ($configuration["emailPassword"]);
        $username = trim ($configuration["username"]);
    
        if(!defined('PHP_EOL'))
            define('PHP_EOL', '\r\n');
    
        $form_email = ((array_key_exists('Email', $_REQUEST) && !empty($_REQUEST['Email'])) ? cleanup_email($_REQUEST['Email']) : '');
    
        $to = $form['email']['to'];
        $subject = $form['subject'];
        $message = get_email_body($subject, $form['heading'], $form['fields'], $form['resources']);
        $headers = get_email_headers($to, $form_email); 
    
        // $sent = @mail($to, $subject, $message, $headers);
    
    
    
        $mail = new PHPMailer(true);                              // Passing `true` enables exceptions
    
        try {
            //Server settings
            //$mail->SMTPDebug = 2;                                 // Enable verbose debug output
            $mail->isSMTP();                                      // Set mailer to use SMTP
            $mail->Host = 'smtp.gmail.com';                       // Specify main and backup SMTP servers
            $mail->SMTPAuth = true;                               // Enable SMTP authentication
            $mail->Username = $username;                          // SMTP username
            $mail->Password = $emailPassword;                          // SMTP password
            $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
            $mail->Port = 587;                                    // TCP port to connect to
    
            //Recipients
            $mail->setFrom('info@example.com', 'Mailer');
            $mail->addAddress('john@example.com', 'User');     // Add a recipient
            //$mail->addAddress('ellen@example.com');               // Name is optional
            //$mail->addReplyTo('info@example.com', 'Information');
            //$mail->addCC('cc@example.com');
            //$mail->addBCC('bcc@example.com');
    
            //Attachments
            //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
            //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
    
            //Content
            $mail->isHTML(true);                                  // Set email format to HTML
            $mail->Subject = $subject;
            $mail->Body    = $message;
            //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    
    
            $sent = $mail->send();
    
            if(!$sent)
                die(get_form_error_response($form['resources']['failed_to_send_email']));
    
            $success_data = array(
                'redirect' => $form['success_redirect']
            );
        } catch (Exception $e) {
            die(get_form_error_response($form['resources']['failed_to_send_email']));
        }
    
        echo get_form_response(true, $success_data);
    }
    

    One important thing to note is that if you don't comment out $mail->SMTPDebug = 2; your mail will send but you will get a server error message instead of seeing the mail as successfully sent.

    Also, I hard coded the email I'm sending to as it will not change but if you want to rely on Muse to do that you can use the $to variable.

    So to recap, make sure you have a lamp stack (Linux/Apache/PHP/MYSQL) installed on your server. No changes to any config or ini files are required.
    Secondly, download the zip from PHPMailer and copy to your server.
    Thirdly modify the function shown above in form_process.php

    That worked for me and my emails are sending correctly.

    The one remaining problem I have is very specific to my use case but it seems if you are using Amazon Cloudfront the dependencies are not cached properly and some problems occur. This is only if your are using Cloudfront. You can test by bypassing Cloudfront and it should work fine. Working on a fix with Cloudfront.

    Hope this is of use to somebody.