简体   繁体   中英

phpmailer works on localhost but not on live server

I have form submition with ajax and phpmailer.

On localhost all works great. I recieve the response (the echo from the php file) and get the mail.

On live, I dont get the mail and as a response I get the whole php file.

I use amazon server.

My thoughts are that this is something with the server but I dont know where to start from.

here is the ajax function

$.ajax({
            url: 'mail/contact_me.php',
            type: 'POST',
            dataType:'text',
            data: {data: JSON.stringify(getData())},
            success:function(response){
                $('#success').text(response);
            }

        });

and the phpfile

 <?php
require 'PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'myemail@gmail.com';
$mail->Password = 'mypassword';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;

$mail->setFrom('myemail@gmail.com','name');
$mail->addAddress('myemail@gmail.com');
$mail->addReplyTo('someemail@gmail.com');
$mail->isHTML(true);

$mail->Subject = 'My Subject';
$mail->Body = $message;

if (!$mail->send()) {
    echo 'Error';
} else {
    echo ' Thank you for contact us';
}

}

I think the php is not working correctly. Have you configured the web server correctly? make sure php was installed and enabled in your web server. If you are using Apache, check the mod_php installed. In Nginx, check php5-fpm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM