I'm not sure if the issue with with Postfix, MediaWiki, LAMP or what. Basically I configured an extension for MediaWiki for AccountRequest and it's supposed to send an email out to the user that created to give them login information. Emails aren't sent out. I figured it might be something to do with settings in localsettings.php but when I add the $wgSMTP array listed below but with my info I start getting [3b2f8024] 2015-11-24 20:19:31: Fatal exception of type "MWException" showing up on mediawiki.
$wgSMTP = array(
'host' => "mail.example.com", // could also be an IP address. Where the SMTP server is located
'IDHost' => "example.com", // Generally this will be the domain name of your website (aka mywiki.org)
'port' => 25, // Port to use when connecting to the SMTP server
'auth' => true, // Should we use SMTP authentication (true or false)
'username' => "my_user_name", // Username to use for SMTP authentication (if being used)
'password' => "my_password" // Password to use for SMTP authentication (if being used)
);
If I leave the localsettings.php settings as enabled and all that it will act like it works but users never get the email.
$wgEnableEmail = true;
$wgEnableUserEmail = true; # UPO
$wgEmergencyContact = "apache#10.00.000.000";
$wgPasswordSender = "apache#10.00.000.000";
$wgEnotifUserTalk = true; # UPO
$wgEnotifWatchlist = false; # UPO
$wgEmailAuthentication = true;
Wondering of a good workaround for this or if someone can point me in the right direction to get this fixed that would be awesome. I've spent hours googling without any results. If my question isn't clear or you need more information please just ask.
Check that the SMTP server is actually reachable. With your $wgSMTP settings, do:
telnet mail.example.com 25
and see if you can connect. If not, either there is no SMTP server running there or there is a firewall. Double check the SMTP host and port, check instructions on how to open firewall in your distribution.
Related
I wanted to rotate the origin IP addresses in an email script, it is used to send notifications to my customers.
My server comes with 5 ip addresses, so I created an array of IPs and while sending the IP address changed randomly, in this array I do not include the main server IP.
This was working fine until last december, I have not made any change nor update (I am not sure if there was any automatic)
Here is the script:
$iparray = array(
'163.xx.217.xx',
'164.xx.217.xx',
);
$ips = $iparray;
$keyip = array_rand($ips);
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "none";
$mail->Host = $ips[$keyip];
$mail->Port = 26;
$mail->AddAddress($recipient);
$mail->Username=$senderemail;
$mail->Password=$senderpass;
$mail->SetFrom($senderemail,$sendername);
$mail->AddReplyTo($senderemail,$sendername);
$mail->AddBCC('smtp#xxxxx.co');
$mail->Subject = 'the subject';
$mail->MsgHTML('the message);
Note that $mail->Host was an IP randomly selected from the array, when checking on the message received, I used to get this:
spf=pass (google.com: domain of test#xxxxxxx.co designates 163.xx.217.xx as permitted sender) smtp.mailfrom=test#xxxxxxx.co
However, since December, the SPF check is being made on the server main IP, instead of any of the selected IP in the array, which I do not want.
This was working properly but all of the sudden it changed, could it be Gmail servers? Could it be something to be configured in the server?
In order to send emails, I use Exim, installed on a Centos server, managed via WHM.
I am not trying to spoof any address, all IP addresses are mine, I just need to make sure they rotate on every email sent, and I could do it but now I am not sure what to change to make it work again.
Thanks for all your help
Binding to an IP happens when the socket is created. You can control this by setting the options that get passed to stream_context_create() in the PHPMailer's SMTP class:
$mail->SMTPOptions = [
'socket' => [
'bindto' => "$bound_ip:0",
],
];
Where $bound_ip is a literal IPv4/IPv6 address, the result of gethostbyname('your-domain.example'), etc. Using 0 for the port allows the system to select the port normally. See the bindto docs for more info.
A SPF check is not made through declaring "everything is fine" in the mail, but through DNS records. Have a look at a SPF checker like https://mxtoolbox.com/spf.aspx to see whether all five of your IP adresses are listed in the SPF record for your outgoing domain.
This is more of a networking question rather than PHP. A remote host like Gmail will only see the outgoing public IP from your mail server. If you connect to one of the original random IPs but the outgoing traffic is being routed so that the traffic is originating from the server's main IP, then that's all that Gmail is going to see. You need to look into your networking configuration to see if there have been any recent changes in that regard.
EDIT: I'll add that my answer -is- somewhat vague, but that's because we don't know what your networking setup is like. You should probably ask this question over at ServerFault:
https://serverfault.com/
the solution was not directly in te PhpMailer, but as I am usin Exim as MTA, the answer is to set exim to read the IP from etc/mailips, and you can even map individual domains to any of your server IP address
[UserFrosting 0.3.x]
I just set up UserFrosting, and everything looks to be working, except one tiny thing...
When a user goes to register, there's an error "Fatal error attempting mail, contact your server administrator"
In the config-userfrosting.php, the smtp section is filled out as:
'mail' => 'smtp',
'smtp' => [
'host' => 'smtp.scottywcreates.com',
'port' => 465,
'auth' => true,
'secure' => 'ssl',
'user' => 'userfrosting#scottywcreates.com',
'pass' => '------'
],
(password blacked out)
Why am I getting this error?
The message that the user sees is just a generic error message, indicating that there was some problem with the mail server. It purposefully avoids giving specific details, that you may not want to disclose to the general public.
To find out the specific error condition, you will need to check your PHP error log. Please check with your particular server configuration to find the location of the PHP error log.
UserFrosting uses PHPMailer to send mail. By default, PHPMailer doesn't output any detailed SMTP error information, so you will likely see a generic exception message in the error log as well (for example, "SMTP Error: Could not authenticate.")
To obtain more detailed error information, you can hack userfrosting/models/Notify/Notification.php and change PHPMailer's default settings. Add the following configuration values to the other SMTP configuration values:
$mail->Debugoutput = 'error_log';
$mail->SMTPDebug = 4;
This will tell PHPMailer to dump very detailed connection and error information to the PHP error log. Once you do this, you should be able to see why exactly your SMTP server is rejecting UserFrosting's emails.
Common reasons that SMTP fails:
Many SMTP servers require that the authenticated account (in your case, userfrosting#scottywcreates.com) matches the From address in the actual email. By default, account verification emails are sent from the "Account Management Email" address set under Configuration -> Site Settings. So, you might try checking that it matches the address you use to authenticate in config-userfrosting.php.
Using the wrong port or authentication method. See the Email Troubleshooting wiki.
I'm trying to send an email when a form is submitted. I'm using PHPMailer to send the mail using the below configuration.
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'mail.example.in';
$mail->Port = 25;
$mail->SMTPAuth = true;
$mail->Username = 'user#example.in';
$mail->Password = 'password';
$mail->setFrom("user#example.in" , "User");
$mail->addAddress('receiver#example.in', 'Receiver');
$mail->addBCC('anotheruser#somedomain.com', 'Another user');
$mail->AddReplyTo('user#example.in', 'User');
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;
if($mail->send())
echo "Your request has been received. We will soon contact you.";
else echo "Unable to send your request. Please try again";
This works fine in localhost. But, when I deploy it to my server (example.in) I get the below exception.
SMTP ERROR: Failed to connect to server: Connection timed out (110)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
--EDIT--
I tried connecting to the SMTP server using telnet command, but I'm unable to add the recipient. I get the below error?
Last login: Fri Sep 16 11:08:06 on ttys000
admin:~ admin$ telnet mail.example.in 25
Trying 111.91.153.112...
Connected to mail.example.in.
Escape character is '^]'.
220 fbs-ho-mailserver.example.in ESMTP Service (Lotus Domino Release 8.5.3FP3) ready at Fri, 16 Sep 2016 11:36:01 +0530
HELO example.in
250 fbs-ho-mailserver.example.in Hello example.in ([111.91.127.222]), pleased to meet you
MAIL from: marketing#example.in
250 marketing#example.in... Sender OK
RCPT to: john.hh#gmail.com
554 Relay rejected for policy reasons.
-- EDIT --
I was able to setup this account in outlook. I'm really confused what's happening.
Your error says:
SMTP ERROR: Failed to connect to server: Connection timed out (110)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
So let's look at https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting :
"SMTP Error: Could not connect to SMTP host."
This may also appear as SMTP connect() failed or Called Mail() without
being connected in debug output. This is often reported as a PHPMailer
problem, but it's almost always down to local DNS failure, firewall
blocking (for example as GoDaddy does) or other issue on your local
network. It means that PHPMailer is unable to contact the SMTP server
you have specified in the Host property, but doesn't say exactly why.
It can also be caused by not having the openssl extension loaded (See
encryption notes below).
Some techniques to diagnose the source of this error are discussed
below.
GoDaddy
Popular US hosting provider GoDaddy imposes very strict (to the point
of becoming almost useless) constraints on sending email. They block
outbound SMTP to ports 25, 465 and 587 to all servers except their
own. This problem is the subject of many frustrating questions on
Stack Overflow. If you find your script works on your local machine,
but not when you upload it to GoDaddy, this will be what's happening
to you. The solution is extremely poorly documented by GoDaddy: you
must send through their servers, and also disable all security
features, username and password (great, huh?!), giving you this config
for PHPMailer:
$mail->isSMTP();
$mail->Host = 'relay-hosting.secureserver.net';
$mail->Port = 25;
$mail->SMTPAuth = false;
$mail->SMTPSecure = false;
GoDaddy also refuses to send with a From address belonging to any aol,
gmail, yahoo, hotmail, live, aim, or msn domain (see their docs). This
is because all those domains deploy SPF and DKIM anti-forgery
measures, and faking your from address is forgery.
You may find it easier to switch to a more enlightened hosting
provider.
The problem - rather the two unrelated problems - that you're experiencing are quite straightforward:
SMTP ERROR: Failed to connect to server: Connection timed out (110)
SMTP connect() failed.
and you have verified that the server is indeed accepting connections:
I tried connecting to the SMTP server using telnet command
Last login: Fri Sep 16 11:08:06 on ttys000
admin:~ admin$ telnet mail.example.in 25
Trying 111.91.153.112...
Connected to mail.example.in.
Your script cannot connect to the SMTP server when run from its production server.
The likely cause is that the production server has a firewall that, to avoid abuse, prevents any connection to the outside. The server can serve Web requests, but no more.
If your test had verified that port 25 was not responding, then (after checking that the host address was correct) you could have tried telnet mail.example.in 587 instead. If that worked, it could have meant that the server is not accepting insecure connections (port 25) but is accepting secure connections. With PHPMailer you could then have tried activating secure connection:
$mail->SMTPSecure = 'tls';
or
$mail->SMTPSecure = 'ssl';
If that does not work, you might still have a firewall issue; or you might need to look at phpinfo() and verify you do have OpenSSL support available in PHP.
What you need to do
ask the IT people that maintain the production server to open the firewall;
more promisingly, ask them how to send emails from that server. Chances are that you need to use the mail() function, or use localhost or 127.0.0.1 as SMTP server. Then the emails will go out through your production server's service network.
They might tell you that port 25 is not allowed, but port (say) 465 or 567 would be allowed. You will have to update your configuration and/or add TLS/SSL accordingly (see above).
or you might be allowed to connect to a third party SMTP server of which you will have to supply the IP address, to allow the IT guys to open a suitable firewall window. Then the emails will go out through the third party server.
The second problem (possibly NOT a problem)
250 marketing#example.in... Sender OK
RCPT to: john.hh#gmail.com
554 Relay rejected for policy reasons
Also to avoid abuse, SMTP Servers will not let everyone connect and send emails, but only their own customers. I see that in the PHPMailer configuration you specified an user and a password. In the telnet session you did not. So it might well be that PHPmailer could send, but not connect, while your telnet can connect, but not send.
Once you solve the connection problem, your authentication problem will either be solved or will have gone away (because you'll be using a different server supplied to you by the IT guys, for example localhost).
The third problem (might never arise)
A third way of abusing services is over-use - sending too many emails to too many people. Verify with the IT guys what the acceptable policies are for sending emails.
Problems, problems
Other things to look into are the credibility of the source (you might want to send emails on behalf of some domain which has not designated your SMTP server of choice as permitted sender), and the confidentiality of the data (even with TLS/SSL connections, if you are given localhost as the SMTP server, your IT guys will have complete, unfettered, undetectable access to any email you send. You might, or might not, be okay with that).
1st quote (from ibm community):
john.hh#gmail.com was a member of a group (Reject) that was listed in
gmail.com's "Deny messages intended for the following internet
addresses" field (in the destination server's Domino Configuration
document's Router/SMTP, Restrictions and Controls, SMTP Inbound
Controls tab's "Inbound Intended Recipient's Controls" section).
Removing Mary's hierarchical name (Mary Jones/ABC) from the members
list in the Reject (group) document allows Mary to receive messages
from the Internet.
2nd quote:
Most mail servers, to prevent them being used as anonymous spam
relays, are configured only to relay mail from certain hosts.
It's a bad idea to use your own SMTP.
Depending of what you have to do with it, you have some great chances to have your emails blocked in some ways or marked as SPAM. And you will have to spend some times to keep your server up to date.
Use online services that are white-listed for every provider and that expose API to send your transactionnal mails :
https://www.mailjet.com/
http://mailchimp.com/
...
They often propose a free account for small volume (under 2000 emails per days).
Using the API is quite trivial and can be put in place in some minutes (ex : https://dev.mailjet.com/)
Ask to your hosting provider if smtp is enabled on not on that server.I had same issue before for smtp and curl both.Contact hosting provider.
What's the phpmailer version?
You might forget to add this line
$mail->IsSMTP(); // use SMTP
after you initiate $mail.
Have a try.
So you have a GoDaddy server and you want to send email through your newly acquired SMTP Relay. Well “you can’t” is probably what you are going to find if you do some poking around Google.
If you poke around a little more you will probably find GoDaddy’s official solution is to use their internal mail relay. This is not ideal, because of arbitrary barriers they have set, such as this one:
Our dedicated servers have an outbound email limit of 1000 per day. If
you need to send more than 1000 emails per day, please call Customer
Support or open a support ticket to request a higher limit.
Quick and Working Solution: Get SMTP Relay that supports sending emails using HTTP API.
My Suggestion: (A simple and effective working solution, I am using personally)
Signup for an account in Sendgrid. Sendgrid provides free 12k emails per month, and I think that should suffice any basic needs.
First Step: Sendgrid will ask you to add few DNS records to authenticate you for sending emails on behalf of that host. So do it.
Second Step Step: Configure White Lables https://sendgrid.com/docs/User_Guide/Settings/Whitelabel/index.html (This is not important, but it will give professional look to the emails you are sending)
Third Step: Generate API keys
You can manage your API Keys from the SendGrid Customer Portal. Additionally, you can manage your API keys via the API itself.
Forth Step: Go ahead and write our codes.
Sending mails using PHP on sendgrid using this library available on github is easy:
// using SendGrid's PHP Library
// https://github.com/sendgrid/sendgrid-php
require 'vendor/autoload.php';
$sendgrid = new SendGrid("SENDGRID_APIKEY");
$email = new SendGrid\Email();
$email->addTo("test#sendgrid.com")
->setFrom("you#youremail.com")
->setSubject("Sending with SendGrid is Fun")
->setHtml("and easy to do anywhere, even with PHP");
$sendgrid->send($email);
How this works
GoDaddy blocks port 25, 2525, 587 and 485 which are ideal ports for SMTP. So we are using the port 80/443 and requesting the sengrid's API to send the email on our behalf behalf using port 80, and yes, we fooled GoDaddy.
I think within a few steps we can get this working properly.
In your Godaddy/Hostgator Cpanel > Select MX records > Select Domain in question > Select "Remote Mail Exchanger"
You can test mail delivery at this time, issue may be resolved.
I am sure it is set up right but trust me when it comes to good ole Cpanel, PhpMailer and Godaddy/Hostgator. It's a place where common sense makes no sense.
replace:
$mail->Host = 'mail.example.in';
with:
$mail->Host = 'localhost';
I believe this should resolve any issues assuming things like login credentials are valid.
I faced similar timeout issue , the reason was my hosting provider (Linode) .
TLDR; SMTP restrictions are in place by default for Linode on accounts created after November 5th 2019. You'll need to configure rDNS for your instance and open a Support ticket confirming CAN-SPAM compliance, and Support should lift the restrictions pretty quickly. I guess many people face this issue because of smtp restrictions
Timeout error is typical of packets dropped, so could be firewall issues between web server and SMTP server.
If you got ssh access to your server, you can try to connect to smtp using:
telnet <smtp server> 25
On timeout error even with telnet, you're quite sure that the problem is on network/firewall side.
You need to change some setting in your php.ini :
upload_max_filesize = 2M
;or whatever size you want
max_execution_time = 60
; also, higher if you must - sets the maximum time in seconds.
Were your PHP.ini is depends on your enviroment, more information:
reference
OR
Place this at the top of your PHP script and let your script loose
ini_set('max_execution_time', 600); //600 seconds = 10 minutes or set your time
I got your point. Same issue happen with me , I have just add one line and its working for me. please use ,
$mail->SMTPSecure = 'ssl';
and configure your setting according to ssl . Also properly check mail configure at your serve end.
I'm trying to send an email using PHP Pear. It works when I send email using Gmail with this settings:
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'username#gmail.com',
'password' => 'password!2016'
));
But before I make this work, I have to "allow less secure apps" to access my account, which you can read here on how to do it.
I tried to use an Outlook account with this settings:
$smtp = Mail::factory('smtp', array(
'host' => 'tls://smtp.office365.com',
'port' => '587',
'auth' => true,
'username' => 'email#domain.org',
'password' => 'greatPasswordComesWithGreatResponsibilities'
));
but I get this error:
Failed to connect to ssl://smtp.office365.com:587 [SMTP: Failed to connect socket: fsockopen(): unable to connect to ssl://smtp.office365.com:587 (Unknown error) (code: -1, response: )]
I checked the official article by Microsoft regarding their SMTP settings. So I thought I have the right settings, but it's not working.
Am I missing something? Why do I get this error? Is there a setting I have to configure in my outlook account, like with the Gmail, before a third party app be allowed to send email?
This may not help but the title of your post just said Outlook account but the link and smtp settings refer to Office365 for Business accounts. I can't shed any light on the business account but if you actually have a personal Outlook.com account the settings are different. And, there is an option on the account you must change to enable pop/smtp access as you did with gmail.
The official Microsoft article is:
https://support.office.com/en-us/article/Add-your-Outlook-com-account-to-another-mail-app-73f3b178-0009-41ae-aab1-87b80fa94970?ui=en-US&rs=en-US&ad=US&fromAR=1
But, the summary is the smtp server is smtp-mail.outlook.com and to enable pop/smtp in your Outlook account look for Options > Managing your account > Connect devices and apps with POP.
Update:
If you are actually using business account, you should check this post which claims to have it working: https://stackoverflow.com/a/26004690/2891120
The key item in his code is he doesn't have "tls://" in front of the host name. I have a consumer outlook account and get a similar socket failure to you with tls:// prefix. If I remove that prefix I get much farther (set debug=true in factory) but fail later with an auth failure. Using 5.2.16 PHPMailer instead I successfully send mail but the headers leave me worried about spam rejection rates (no DKIM, SPF was softfail for my AWS entity, warning about -f, and others). And, the email did end up in the junk folder of my other test recipient #outlook.com. But I digress.
Failed to authenticate password. Error: 534-5.7.14 Please log in via your web browser and then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 wv1sm5867206pab.37 - gsmtp
function index() {
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'gauravkwt#gmail.com',
'smtp_pass' => '92135108845129',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('gauravkwt#gmail.com', 'Gaurav kwatra');
$this->email->to('gaurav.kawatra#ymail.com');
$this->email->subject('This is an email test');
$this->email->message('Emial Testing');
//$this->email->initialize($config);
if($this->email->send())
{
echo 'Your email sent...!!!! ';
}
else
{
show_error($this->email->print_debugger());
}
}
//end of code
I use above code to send mail from codeigniter....I have an error...Failed to authenticate. Password is correct.
You would need to go to your account settings https://www.google.com/settings/security and you would need to enable Access for less secure apps which helps to use the google smtp for clients.
Please have a look here too
If it still doesn't work even after enabling less secure apps - you should login to your security area within your Google account and see if your device has been blocked. Google blocked my server so I then went to https://accounts.google.com/b/0/displayunlockcaptcha and it now allows me to send. Nothing to do with the username or password but Google blocking the device access.
I have got the same problem and the solution I found by unblocking the google captcha. Google blocked my server IP sending email using their SMTP. So I had to unblock it.
To unblock the google captche:
Open the link https://accounts.google.com/DisplayUnlockCaptcha.
Enter your username and password to sign in to your gmail account that you have used for the SMTP configuration.
You will get the button on google like the image bellow.
Then you need to allow access to your google account by clicking the continue button.
Note: You might get blocked again and anytime if you make some spam and your receiver email addresses are not exist.
So if anyone knows how to make it unblock permanently without by any google setting or something, it would be really appreciated.
One of the reason can be the cpanel settings. Please try:
Login to CPanel
Tweak Settings > All>
"Restrict outgoing SMTP to root, exim, and mailman (FKA SMTP Tweak)
And select "off"
Although it was a question five years ago, today I encountered the same situation and found the correct answer as a supplement.
All CI settings are correct, the only problem lies in Google ’s security settings, go to
https://myaccount.google.com/security
And set Sign in using App Passwords, which can find options, select mail, and choose other in the options of the device, enter the name at will, such as PHP / CI, and then Google will generate a password for you to use.
Please replace the password you entered in the CI email with this password, cheers.