How do i connect to mailserver? - mail-server

i'm trying to create a contact form,with a code from a website,but when i open it with localhost,it give me an error:
Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in D:\programe\wamp\www\website\trimite.php on line 41
Well,this is the line 41:
mail($catre, $subiect, $mesaj, $headere);
It is anything wrong? Maybe it's because i need a database,or i dont know,im not really good at this.

Probably this is way too old, but since I have an easy fix (I guess) I will give it a shot:
If you only want to try the code (mail function) and see if the email is actually sent, in your dev environment, you can try to accomplish that with this small tool: http://www.toolheap.com/test-mail-server-tool/
I used it several times in the past when I had no proper smtp mail server configuration available and I had to test in a few seconds that my code was behaving properly.
I hope it helps.

Related

Couldn't get any response when sending request to Postman

When I send a Post request to Postman, I get Could not get any response
error. The call is something like the following:
https://localhost:8080/ProjectName/ClassName/MethodName
My colleague tries exactly the same endpoint and there is no problem for him. It seems that the problem is something with the settings on my laptop. I tried the endpoint with Insomnia. But I still get the same error.
In the meantime, when I have some calls which do not require port number, there is no problem. I have the problem just with the calls which require me to mention the port number directly.
I should also mention that I'm using Docker and when I try to set a remote debug for my project, I get an error Unable to open debugger port (localhost:8080). I'm not sure if these problems are related. But I think there is something wrong with my port settings. Any help is appreciated.
Thanks in advance,
In my case, the problem was a stupid mistake from me.
As I said, I'm using Docker. I had used docker-compose.override.yml and had defined the ports there. But I had named the file wrongly docker-compose-override.yml (using a dash line instead of dot). So, the ports were not set correctly.

I cannot send mail with SwiftMailer or PHPMailer from Localhost using gmail

I have recently been unable to send out mails through php on localhost. I use PHPMailer and SwiftMailer in different parts of the application.
With SwiftMailer I get this:
Connection could not be established with host smtp.gmail.com [ #0]
With PHPMailer, the message is:
SMTP Error: Could not connect to SMTP host.
My settings on SwiftMailer look like this:
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
->setUsername(APP_GMAIL_EMAIL)
->setPassword(APP_GMAIL_PWD);
I have gone through several threads here at SO and elsewhere, and tried many 'fixes' but the error messages remain the same. Some "solutions" I've tried are:
Enable OpenSSL inphp.ini (It was previously off)
Change smtp.gmail.com to smtp.googlemail.com
Replace smtp.gmail.com with certain gmail IP addresses
Replace smtp.gmail.com with gethostbyname('smtp.gmail.com')
Add ->setSourceIp('0.0.0.0') to the instantiation code above, after setUsername and setPassword
This code was previously working, and I'm not sure what could have broken the function. As part of troubleshooting, I have just confirmed that a similar code on Linux shared hosting is emailing satisfactorily, suggesting that the problem is somehow from my environment. Thus, I even tried different sources of internet access, in case it's an ISP thing.
How can I crack this nut?
I have been able to overcome the problem, at least with SwiftMailer. The solution must have arisen after my PHP upgrade from 5.2.5 to 5.6, which is the version I have currently. The insight came from this page:
https://github.com/swiftmailer/swiftmailer/issues/544
If you are using PHP 5.6, the error does occur because of the "SSL
context options" used for the stream context in swiftmailer. IN PHP
5.6 verify_peer and verify_peer_name the default was set to TRUE, so PHP checks the SSL certificate. It is currently not possible to
disable it in swiftmailer using some options.
You could disable the SSL check by modifying the function
"_establishSocketConnection" in StreamBuffer.php. Add these lines
before stream_socket_client command:
$options['ssl']['verify_peer'] = FALSE;
$options['ssl']['verify_peer_name'] = FALSE;
It would be great if these options could be set without hacking the
code.
Thanks to https://stackoverflow.com/a/29448735/2554788 who first pointed me to the said post.
By the way, the path to StreamBuffer.php is:
\lib\classes\Swift\Transport
A word of warning though: this solution is based on hacking the code inside a class, and will probably fail, say, after upgrading SwiftMailer versions (in which case you'd need to go back and hack the code again).
Perhaps, more current versions of SwiftMailer have put their acts together in PHP 5.6 (I use SwiftMailer 5.1 currently). I intend to try an upgrade ASAP, hoping there has been an elegant fix for this issue.

How to get e-mails to work on phpBB with CentOS 6? Experiencing PHP Error

So, I have a phpBB forum on CentOS 6, however there is a problem. E-mails are simply not working.
I tried using e-mails on domain such as admin#domain.com, and I would get this error:
E-mail error
» EMAIL/PHP/mail()
/adm/index.php
so I trued using SMTP with different SMTP hosts and settings, nothing has worked, I would simply get this error:
E-mail error
» EMAIL/SMTP
/adm/index.php
Could not connect to smtp host : 0 : php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
Errno 2: fsockopen(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution at [ROOT]/includes/functions_messenger.php line 1030<br />
Errno 2: fsockopen(): unable to connect to smtp.mail.com:25 (php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution) at [ROOT]/includes/functions_messenger.php line 1030
I got the errors from PHP Error Log from PHP
Oddly enough, the e-mails appear on my VPS in var/spool/mail/root file.
2 people have told be that this may be a DNS issue, I suspect this being true, as I, for some reason, couldn't use "wget" on my VPS, so I set Nameservers in /etc/resolv.conf and suddenly another problem I was experiencing, "could not get latest phpBB version" or something like that, was fixed. So, if that was fixed with such a solution, I would assume this would have something to do with it too.
And, I asked my host about it, they said "everything is virtualized" and how they have no actual control over it (in a sense that it is their configuration's fault) and how they do not support 3rd party software, even though this is not a software issue. And prior to that they said that they talked to "level 3 Linux admin" and how the admin said it is PHP/Apache issue.
I am losing my mind over this. It is a good machine for a good price with a game panel as we are hosting a game server, and it would really be a bother to move it all elsewhere.
Also, full talk and information on phpBB forums can be found here:
https://www.phpbb.com/community/viewtopic.php?f=46&t=2257586
Check your SMTP settings, make sure its set to the correct client (both on your DNS and within phpbb in General-Client Communication-Email Settings). If you have to use an authenticated account, verify that the username and password you are using is correct by typing it into a word doc to see spelling and copy/pasting it into the fields. In some cases, SMTP will only work with authenticated accounts.

emails from localhost using mocksmtp

I have been trying to setup email on my local machine. After some advice that it is a rather involved thing to set up, I started to look around for a solution to my problem and came across an app called mocksmtp. I have followed this tutorial to set it up. But i'm getting errors.
of
send-mail: warning: valid_hostname: invalid character 64(decimal): my.email#address.com
send-mail: fatal: file /etc/postfix/main.cf: parameter myhostname: bad parameter value: my.email#address.com
Looking at this page I believe the problem is with /etc/postfix/main.cf
myhostname = my.email#address.com
but what value should I change the email address to to make this work? I have tried a few option but nothing has worked for me and in that post the only problem was a period at the end.
The tutorial is a valid and helpful page and would have worked perfectly had telnet localhost 1025 been enabled. Enabling telnet got it working. To do this telnet localhost 1025 worked for me
Looks like you're trying to enter an entire email in a parameter meant only for a host name. You should only have address.com, not my.email#address.com. It's not for a full email. You're setting this up as a server, to catch everything for a host, not just one particular email.

PHP Mail shows SMTP Error

I have tried many mailing scripts in php,But my server always shows SMTP error.I am using PHP5.Any please help..
I think you are trying your code on local machine, try upload it to someserver than try ...