0

This is the Code , its working on local host but not working on live server

isSMTP(); i already remove it on live server but still dosent work

<?php
    use PHPMailer\PHPMailer\PHPMailer;
    
    require 'PHPMailer/src/Exception.php';
    require 'PHPMailer/src/PHPMailer.php';
    require 'PHPMailer/src/SMTP.php';    

    //Create an instance; passing `true` enables exceptions
    $mail = new PHPMailer(true);

    $alert = "";

    if(isset($_POST['submitit'])){
        $name = $_POST['name'];
        $email = $_POST['email'];
        $phone = $_POST['phone'];
        $subject = $_POST['subject'];
        $message = $_POST['message'];



        try {
                       
            // $mail->isSMTP();                                            
            $mail->Host       = 'mrcreativeproductions.com';                     
            $mail->SMTPAuth   = true;   
            $mail->Username   = 'mrcreativeproductions1@gmail.com';   
            $mail->Password   = 'jhmsxriwesuqbpnk';        
            //  $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;   
            $mail->SMTPSecure = "tls";
            $mail->Port       = 587;  
            
            
            $mail->setFrom('wilfredpeace715@gmail.com');
            $mail->addAddress('mrcreativeproductions1@gmail.com');     //Add a recipient

            $mail->isHTML(true);
            $mail->Subject = 'message received from contact:'. $name;
            $mail->Body = "Name: $name <br> Phone: $phone <br> Email: $email <br> Message: $message";

            $mail->send();
            $alert = "<div class='alert-success'><span>Message Sent! thnx</span></div>";

            // $mail->addReplyTo('info@example.com', 'Information');
            // $mail->addCC('cc@example.com');
            // $mail->addBCC('bcc@example.com');

            //Recipients
        } catch (Exception $e) {
            $alert = "<div class='alert-error'><span>'.$e->getMessage().'</span></div>";
        } 


    }

?>
  • Enable the debug mode, and see what output that gets you. – CBroe Jan 16 '23 at 12:24
  • 2
    Please define _not working_ – Justinas Jan 16 '23 at 12:25
  • @CBroe http://mrcreativeproductions.com/contact.php 500 (Internal Server Error) is found – Wilfred stewart Jan 16 '23 at 12:30
  • Not really what I meant, but anyway - if you get a 500, then the first thing you should do is go check the error log an see what actually caused it. – CBroe Jan 16 '23 at 12:31
  • 2
    `$mail->Password = '....';` Is that your real password? If so, you might want to set a new one – brombeer Jan 16 '23 at 12:39
  • Check your error logs, enable `isSMTP()` again and post your output with `$mail->SMTPDebug = 3;`. Then [read the PHPMailer troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting). – Synchro Jan 16 '23 at 12:44
  • I've generated it from google add a password (App passwords let you sign in to your Google Account from apps on devices that don't support 2-Step Verification.) @brombeer – Wilfred stewart Jan 16 '23 at 12:44
  • That's not going to make much difference if your script is broken; check your logs, enable debug output. – Synchro Jan 16 '23 at 12:47
  • I've just referred the following hyperlink (https://www.youtube.com/watch?v=iqByx5cxDEU)but it didn't work on the live server but it's working on localhost @Synchro – Wilfred stewart Jan 16 '23 at 12:54
  • First of all.. use $mail->SMTPDebug = 1 – Blazej Kita Jan 16 '23 at 13:36
  • @BlazejKita, no don't use `SMTPDebug = 1`; it will not show you what the server is saying, nor any TLS connection info. Use 3, like I said. – Synchro Jan 17 '23 at 13:10
  • One issue I can see right away from your last comment: you're trying to use a `gmail.com` email address as your from address. That will not work. If you want to send from a `gmail.com` address, you **must** send through `gmail.com` servers. Gmail's DMARC settings do not allow you to spoof your address like that. – Synchro Jan 17 '23 at 13:12
  • SMTP Error: Could not connect to SMTP host. Connection failed. stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed @Synchro – Wilfred stewart Jan 17 '23 at 14:48
  • What happened when you read [the PHPMailer docs on certificate verification failures](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#certificate-verification-failure) and did what it said? – Synchro Jan 19 '23 at 17:48

0 Answers0