0

I am having trouble in sending mail through php mailer, I am easily able to send email on localhost (Wampp) but on live sever I am getting the error:

SMTP Error: Could not connect to SMTP host. failed

 <?php 
    if (isset($_POST['submit'])) {
      # code...
    $customeremail="*************";

    $message=
    'Full Name: '.$_POST['name'].'<br />
    Subject:    '.$_POST['subject'].'<br />

    Phone:  '.$_POST['phone'].'<br />
    Email:  '.$_POST['email'].'<br />
    Comments:   '.$_POST['message'].'
    ';
    require "phpmailer/class.phpmailer.php"; //include phpmailer class

    // Instantiate Class
    $mail = new PHPMailer();

    // Set up SMTP
    $mail->IsSMTP();                // Sets up a SMTP connection
    $mail->SMTPAuth = true;         // Connection with the SMTP does require authorization
    $mail->SMTPSecure = "ssl";      // Connect using a TLS connection
    $mail->Host = "smtp.gmail.com";  //Gmail SMTP server address
    $mail->Port = 465;  //Gmail SMTP port
    $mail->Encoding = '7bit';

    // Authentication
    $mail->Username   = "******"; // Your full Gmail address
    $mail->Password   = "******"; // Your Gmail password

    // Compose
    $mail->From = "*************";
    $mail->FromName = "**********";

    $mail->Subject = "DRIVER AND CAR DETAILS";      // Subject (which isn't required)
    $mail->MsgHTML($message);

    // Send To
    $mail->AddAddress($customeremail, "Recipient Name"); // Where to send it - Recipient
    $result = $mail->Send();        // Send!



    if(!$mail->Send()) {
    echo 'Message was not sent.';
    echo 'Mailer error: ' . $mail->ErrorInfo;
    } else {
    echo 'Message has been sent.';
    }
    ?>

I tried creating a php.ini file and putting extension=php_openssl.dll but its also not working, there are my other websites too, but am getting error in this only, please help me!!

M. Eriksson
  • 13,450
  • 4
  • 29
  • 40
  • Try setting `$mail->SMTPSecure = 'tls';` instead of `'ssl'`. Btw, you said that you "created" a php.ini? There should already be one that PHP uses on the server. And is your server a Windows server or Linux server? `.dll`-files are Windows-only. – M. Eriksson Jul 14 '17 at 11:37
  • not working even after tls !!and I dont know whether its windows or linux ! –  Jul 14 '17 at 11:46
  • You don't know if the server is running Windows or Linux? How and where did you create/edit the `php.ini`-file? How do you connect to the server? – M. Eriksson Jul 14 '17 at 11:48
  • i have login id and password of cpanel ,its of someone else Its a shared hosting account many other websites are also there –  Jul 14 '17 at 11:51
  • If you can't be bothered to base your code on the tested code provided with PHPMailer, and can't be bothered to read the docs, nor read error messages, or run a version less than a ew years old, I have no sympathy. – Synchro Jul 15 '17 at 20:57
  • Possible duplicate of [PHPMailer: SMTP Error: Could not connect to SMTP host](https://stackoverflow.com/questions/3477766/phpmailer-smtp-error-could-not-connect-to-smtp-host) – Synchro Jul 15 '17 at 20:58

0 Answers0