why i am getting SMTP connect failed error in PHPMailer?

26
March 14, 2019, at 10:10 PM

I really don't know what's wrong in my code. I am creating contact us form by which user can send email to me. I already searched all possible answer related to this topic on StackOverflow but nothing works for me... here is the code

<?php
session_start();
require_once 'libs/phpmailer/PHPMailerAutoload.php';
$errors =[];
if(isset($_POST['name'],$_POST['email'],$_POST['message'])){
    $fields=[
        'name'=>$_POST['name'],
        'email'=>$_POST['email'],
        'message'=>$_POST['message']
    ];
    foreach($fields as $field=>$data){
        if(empty($data)){
            $errors[]='The '.$field . ' field is required.';
        }
    }
    if(empty($errors)){
        $m=new PHPMailer;
        $m->isSMTP();
        $m->SMTPAuth=true;
        $m->Host='smtp.gmail.com';
        $m->Username='...@gmail.com';//replace with your email address
        $m->Password='xxxxxxx';//replace with your password
        $m->SMTPSecure='ssl';
        $m->Port=465;
        $m->isHTML();
        $m->Subject ='Contact form Submitted';
        $m->Body='From:'.$fields['name'].'('.$fields['email'].')<p>'.$fields['message'].'</p>';
        $m->FromName='Contact';
        $m->AddAddress('someone@gmail.com','Some one');
        if ($m->send()) {
            header('Location:thanks.php');
            die();
        }else{
            $errors[]="Sorry ,Could not send email.Try again later.";
        }
    }
}else{
    $errors[]= 'Something went wrong';
}
$_SESSION['errors']=$errors;
$_SESSION['fields']=$fields;
header ('Location:index.php');
READ ALSO
Use MacPorts PHP-FPM instead of from build

Use MacPorts PHP-FPM instead of from build

I've used MacPorts to install apache2, php73 and php73-fpm on MacOS MojaveI've updated by

43
Reduce memory usage for big database calls php

Reduce memory usage for big database calls php

I am using this script to cross reference data so that I can retrieve the right data from the database which requires 3 checks of which 2 are run within a for loop

53
Trying to Create WP Category Archive on Site the Uses Timber and AJAX Load More Plugin

Trying to Create WP Category Archive on Site the Uses Timber and AJAX Load More Plugin

I inherited a Wordpress website that uses the Timber templating engineI'm not overly familiar with Timber, but I've been able to learn enough to make simple edits to this point

19
How can I receive and parse my mails with php? [on hold]

How can I receive and parse my mails with php? [on hold]

I need to automate checking my emails and parsing information out of the headers with a PHP script, preferably in WordPressHow can I possibly do that? I am a bit of a noob, please help

38