2

This is my code and still it is not sending the mail. What could be the problem?

require 'class.phpmailer.php';// path to the PHPMailer class
require 'class.smtp.php';

            $mail = new PHPMailer();  

            $mail->IsSMTP();  // telling the class to use SMTP
            $mail->Mailer = "smtp";
            $mail->Host="smtp.gmail.com";
            $mail->SMTPSecure='tls';
            $mail->Port =465;             
            $mail->SMTPAuth = true; // turn on SMTP authentication
            $mail->Username = "mymailgmail.com"; // SMTP username
            $mail->Password = "mypassword"; // SMTP password 
            $mail->SMTPDebug = 1;

            $mail->AddAddress("mymail@gmail.com","Title");
            $mail->SetFrom($visitor_email, $name);
            $mail->AddReplyTo($visitor_email,$name);

            $mail->Subject  = "Message from  Contact form";
            $mail->Body     = $user_message;
            $mail->WordWrap = 50;  

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

// header('Location: thank-you.html'); }

andy
  • 1,947
  • 5
  • 27
  • 46
  • See the accepted answer here, it might help http://stackoverflow.com/questions/16048347/send-email-using-gmail-smtp-server-through-php-mailer – marekful Sep 03 '13 at 09:47
  • Still nothing. Could it b a problem with where am hosting my files? – andy Sep 03 '13 at 10:38
  • I'd start looking in the direction to find out why the error message says it was trying to connect to port 110 whereas you attempted to configure PHPMailer to use port 465. – marekful Sep 03 '13 at 11:58
  • [this answer](http://stackoverflow.com/questions/13574166/phpmailer-send-gmail-smtp-timeout) helped me. I used 587 port and 465 didn't work for me. – ivkremer Apr 02 '14 at 18:51

1 Answers1

1

I had similar issue sometime back. It turned out that the connection was attempted using ipv6 address. It worked fine after removing IPv6 address from network interface.