PhpMailer Not Working in Xampp - But Working in Web

Problems with the Mac OS X version of XAMPP, questions, comments, and anything related.

PhpMailer Not Working in Xampp - But Working in Web

Postby Srdrsn » 21. June 2018 14:26

First of all, Before I made that post I am searching my problem for 10 days but I couldnt solved the issue,

My webpage I made it with php in 2013 was working perfectly in web right now, but in localhost Xampp the mail functions and php mailer is not working. Always it fails and displays
SMTP Connect error

My codes are shown below


<?php
include "baglan.php";
require 'admin/class.phpmailer.php';

$firma= $_POST['firma'];
$email= $_POST['email2'];
$iletisim= $_POST['iletisim'];

if( empty($firma) || empty($email) || empty($iletisim))
{
header("Location:iletisim.php");
}

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = 'smtp';
$mail->SMTPAuth = true;
$mail->Host = 'host adress'; // "ssl://smtp.gmail.com" didn't worked
$mail->Port = 587;
$mail->SMTPSecure = 'tls';


$mail->Username = "user name adress";
$mail->Password = "pass";
$mail->CharSet = "UTF-8";
$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->SingleTo = true; // if you want to send a same email to multiple users. multiple emails will be sent one-by-one.

$mail->From = "mail adress";
$mail->FromName = "Tekleme Lastik";

$mail->addAddress("mail adress","User 1");

$mail->addCC("","User 2");

$mail->Subject = "İletisim Mesajı";
$mail->Body = "
<br> $iletisim </br>

<br> Firma: $firma </br>
<br> Email: $email </br>
";
if(!$mail->Send())
echo "Could not be sent<br />PHPMailer Error: " . $mail->ErrorInfo;
else
echo "Sent..";


ob_end_flush();


?>
Srdrsn
 
Posts: 6
Joined: 21. June 2018 14:09
XAMPP version: 7.2.4-0
Operating System: Mojave

Re: PhpMailer Not Working in Xampp - But Working in Web

Postby TonyVier » 21. June 2018 16:27

Hi,

If you use tls, you should not have "ssl://" in front of "smtp.gmail.com"....

You can add :

Code: Select all
$mail->SMTPDebug = 2;


after $mail = new PHPMailer(); to see some more info about errors...

Most likely its a firewall issue....
TonyVier
 
Posts: 43
Joined: 24. May 2018 11:22
XAMPP version: 7.2.5-0
Operating System: Windows 10 pro

Re: PhpMailer Not Working in Xampp - But Working in Web

Postby Srdrsn » 22. June 2018 11:09

Thanks for help, after inserting the code, at the left corner top of the web page small fonter I got that ' Invalid address: '

and in the main frame I got all these below

2018-06-22 09:58:46 SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution (0) SMTP connect() failed. Message Couldnot be sent ( error info )
PHPMailer Error: SMTP connect() failed.


I also think that its about firewall or dns or sth, waiting for your help

Thanks
Srdrsn
 
Posts: 6
Joined: 21. June 2018 14:09
XAMPP version: 7.2.4-0
Operating System: Mojave

Re: PhpMailer Not Working in Xampp - But Working in Web

Postby Nobbie » 22. June 2018 11:46

Which host do you apply?

Code: Select all
$mail->Host = 'host adress'; // "ssl://smtp.gmail.com" didn't worked


That is the critical part, but nobody can fix it for 'host adress'...
Nobbie
 
Posts: 13183
Joined: 09. March 2008 13:04

Re: PhpMailer Not Working in Xampp - But Working in Web

Postby Srdrsn » 22. June 2018 12:08

its just an example, the host adress etc. are all right in the original form
Srdrsn
 
Posts: 6
Joined: 21. June 2018 14:09
XAMPP version: 7.2.4-0
Operating System: Mojave

Re: PhpMailer Not Working in Xampp - But Working in Web

Postby Nobbie » 22. June 2018 12:26

Its not my problem. Good luck.
Nobbie
 
Posts: 13183
Joined: 09. March 2008 13:04

Re: PhpMailer Not Working in Xampp - But Working in Web

Postby TonyVier » 22. June 2018 21:17

Srdrsn wrote:I also think that its about firewall or dns or sth, waiting for your help


It seems your Apache is not allowed to connect, assuming you have the right host.

try something like:

Code: Select all
<?php
$ip = gethostbyname('www.example.com');

echo $ip;
?>


to check...
TonyVier
 
Posts: 43
Joined: 24. May 2018 11:22
XAMPP version: 7.2.5-0
Operating System: Windows 10 pro

Re: PhpMailer Not Working in Xampp - But Working in Web

Postby Srdrsn » 23. June 2018 17:29

The code you gave me what should I write instead of www.example.com

Cause whatever I write in there I mean my host is mail.teklemelastik.com it shows the same as error message infront of invalid adress

just when I wrote there localhost it shows ip adress of the localhost


waiting for ur help and also thanks for the help :) I am about to get crazy about that thing

and I think Most probably its because of Mac os system :S
Srdrsn
 
Posts: 6
Joined: 21. June 2018 14:09
XAMPP version: 7.2.4-0
Operating System: Mojave

Re: PhpMailer Not Working in Xampp - But Working in Web

Postby TonyVier » 24. June 2018 13:14

Srdrsn wrote:The code you gave me what should I write instead of www.example.com


Nothing, you should try it like that.

example.com does exist :)

In this way you can see if your xampp can connect to the "outside world". If the result is 93.184.216.34, it's ok.
TonyVier
 
Posts: 43
Joined: 24. May 2018 11:22
XAMPP version: 7.2.5-0
Operating System: Windows 10 pro

Re: PhpMailer Not Working in Xampp - But Working in Web

Postby Srdrsn » 24. June 2018 16:27

I tried and its returned just www.example.com

it does not returned any ip adress that u mentioned below


Help me please :)
Srdrsn
 
Posts: 6
Joined: 21. June 2018 14:09
XAMPP version: 7.2.4-0
Operating System: Mojave

Re: PhpMailer Not Working in Xampp - But Working in Web

Postby TonyVier » 25. June 2018 00:23

Oh.

Looks like your server can't connect to the outside, sorry I dont have a mac, so....

To be sure run this:

Code: Select all
<pre>
<?php
print_r(dns_get_record("example.com" ,DNS_A));
?>
</pre>


It should return:

Code: Select all
Array
(
    [0] => Array
        (
            [host] => example.com
            [class] => IN
            [ttl] => 9852
            [type] => A
            [ip] => 93.184.216.34
        )

)


If not, somebody with mac knowledge should be able to help you, I hope...
TonyVier
 
Posts: 43
Joined: 24. May 2018 11:22
XAMPP version: 7.2.5-0
Operating System: Windows 10 pro

Re: PhpMailer Not Working in Xampp - But Working in Web

Postby TonyVier » 25. June 2018 00:38

Oh.

https://community.apachefriends.org/vie ... p?p=261021

I suppose you use a VM version..... and this version cannot connect to the Internet...

So you need to install a non VM version...
TonyVier
 
Posts: 43
Joined: 24. May 2018 11:22
XAMPP version: 7.2.5-0
Operating System: Windows 10 pro

Re: PhpMailer Not Working in Xampp - But Working in Web

Postby Srdrsn » 25. June 2018 15:31

TonyVier wrote:Oh.

https://community.apachefriends.org/viewtopic.php?p=261021

I suppose you use a VM version..... and this version cannot connect to the Internet...

So you need to install a non VM version...





I can not thank you enough :) All thanks will be less, Really I am so appreciated so grateful to you...

It is solved :)) Thank you so so much again... It is working so perfectly now and I can continue develop the site :)
Srdrsn
 
Posts: 6
Joined: 21. June 2018 14:09
XAMPP version: 7.2.4-0
Operating System: Mojave


Return to XAMPP for macOS

Who is online

Users browsing this forum: No registered users and 70 guests