getting following error:
SMTP -> ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No such host is known. (0)
SMTP Error: Could not connect to SMTP host. There was a problem sending this mail!
This is my config file setting as I have followed this PHPMailer tutorial
// Configuration settings for My Site
// Email Settings
$site['from_name'] = 'Manish Dekavadiya'; // from email name
$site['from_email'] = 'manish#<my-domain>.com'; // from email address
// Just in case we need to relay to a different server,
// provide an option to use external mail server.
$site['smtp_mode'] = 'enabled'; // enabled or disabled
$site['smtp_host'] = "smtp.<my-domain>.com";
$site['smtp_port'] = 587;
$site['smtp_username'] = "manish#<my-domain>.com";
$site['smtp_password']="<password>";
and used mailer class and an extended class as mentioned in tutorial as following:
/*****sendmail.php****/
// Grab our config settings
require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');
// Grab the FreakMailer class
//echo $_SERVER['DOCUMENT_ROOT'];
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/MailClass.inc');
// instantiate the class
$mailer = new FreakMailer();
// Set the subject
$mailer->Subject = 'This is a test';
$mailer->SMTPDebug = 1;
// Body
$mailer->Body = 'This is a test of my mail system!';
// Add an address to send to.
$mailer->AddAddress('manish.dekavadiya#gmail.com', 'Manish Dekavadiya');
if(!$mailer->Send())
{
echo 'There was a problem sending this mail!';
}
else
{
echo 'Mail sent!';
}
$mailer->ClearAddresses();
$mailer->ClearAttachments();
also getting another error when I tried an example given in phpmailer docs # examples/test_smtp_gmail_basic.php
SMTP -> ERROR: Failed to connect toserver: php_network_getaddresses:
getaddrinfo failed: No such host is
known. (0) SMTP Error: Could not
connect to SMTP host. There was a
problem sending this mail!
so there must be setting or configuration error. there can't be code error.
Is SMTP set up on ? And if so is it configured to listen to smtp..com on port 587? If the server is not set up by yourself it's not uncommon that they listen to mail..com instead. Also, try to connect to port 25 to see if it might be configured to listen to the default smtp port.
The error messages is in any case very clear. The host is not responding to your connection attempt. The reason could be missconfigurations in both the server and in PHP, firewall issues, routing issues, DNS issues etc.
Hopefully this helps someone else out there because I was fighting this same error. First I was getting. I was getting an error that said it couldn't connect(). Then I turned on the debugging and got the error you mentioned. The solution that worked for me was to change the smtp..com to the ip address.
$mail->Host = 'smtp.whateverDomain.com';
to
$mail->Host = 'theIPaddress';
debugging
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
I had this problem a while ago, everything checked out just fine but the problem persisted. A reboot of httpd.service solved it.
Had this issue after restart of computer where docker container with apache webserver was running.
Apache server hosted php code which stopped sending emails after computer restart.
Restarting apache docker container solved the issue.
Related
I have been troubleshooting this issue for the last two months and have gotten no results on how to fix this. I am using PHP 5.6.3 with PEAR 1.10.1, the emailing pages in question worked fine with our 3-party emailing software on our local server only designed to use port 25 for SMTP. Now the PHP pages do reference an XML template that contains all the host, password, and username information. I want to switch to using google email servers with SSL. I implemented the changes provided by my email administrator and change the MX records accordingly. It was functioning properly for two weeks. After that I was getting the following error
"Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error) (code: -1, response: )]".
I have changed the code several times, I removed the ssl://, I have changed the protocol type to TLS with the port number 587, etc. Nothing was working! I reached out to the contractor to construct a simple hard-coded page that just said hello world using the gmail server configuration. He refused and made myself make a simple php page, mind you I had zero background in PHP programming until now, so on a side note entirely happy that this was thrown my way, but regardless I did complete the task. I have a page that sends a simple message, using the smtp server with the account desired using the PHPMailer library. (See the code below)
<?php
require_once 'C:\Webpage\PHPMailer-5.2-stable/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->SMTPDebug = 4; // 2 to enable SMTP debug information
$mail->Host = 'smtp.gmail.com';
$mail->Username = 'username#gmail.com';
$mail->Password = 'XXXXXXXXXXXXXXXXXXX';
$mail->SMTPSecure ='ssl';
$mail->Port = 465;
/*$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
//'allow_self_signed' => true
)
);*/
$mail->From = 'XXXXt#abc.com';
$mail->FromName = 'Example';
$mail->addReplyTo('testing#abc.com','Example');
$mail->AddAddress('user1#xyz.com', 'John Doe');
$mail->Subject = 'Hello World';
$mail->Body ='A test email!';
$mail->AltBody = 'A test email!';
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
?>
Now I know this is not using PEAR, but from this I found out some interesting information that I think is related. The code only works if the line with
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
//'allow_self_signed' => true
)
);
is not commented out it works, but when it is commented out, I receive an error regarding this.
Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed [C:\Webpage\PHPMailer-5.2-stable\class.smtp.php line 299]
So I googled this error and was lead to the php.ini file to change the openssl.cafile and the openssl.capath values. I entered in the download CA certificates and entered the correct pathway for the values, but still it is not working. Am I placing these in the wrong area? Or is there an easier way to fix this issue using the PEAR library? Please any help on this subject will be appreciated!:)
UPDATE(02/20/2018):
I have downloaded the bundle and set the pathway to it's correct location,curl.cainfo ="C:\OpenSSL-Win64\bin\PEM\cacert.pem",openssl.cafile="C:\OpenSSL-Win64\bin\PEM\cacert.pem". I still am getting the error I ran the following check of the ssl locations to see if it was using the php.ini file and got the following.
<?php
error_reporting(E_ALL);
print "\nIf you've got this far without errors then problem is with your SSL config\n";
$calocns=openssl_get_cert_locations();
if (count($calocns)) {
print "Check you've got your cacerts deployed in one of the following locations\n";
foreach ($calocns as $k=>$v) print "$k = $v\n";
} else {
print "You've not configured your openssl installation on this host\n";
}
$calocns=openssl_get_cert_locations();
//var_dump(openssl_get_cert_locations());
?>
Result:
If you've got this far without errors then problem is with your SSL config Check you've got your cacerts deployed in one of the following locations default_cert_file = f:\repo\winlibs_openssl_vc11_x86/cert.pem default_cert_file_env = SSL_CERT_FILE
default_cert_dir = f:\repo\winlibs_openssl_vc11_x86/certs
default_cert_dir_env = SSL_CERT_DIR
default_private_dir = f:\repo\winlibs_openssl_vc11_x86/private
default_default_cert_area = f:\repo\winlibs_openssl_vc11_x86
ini_cafile =
ini_capath =
I seem to be doing this wrong or need to know how to change the locations because those locations are not existent on my computer and I don't understand how it goes to those by default when I changed the pathway in the configuration file itself. Any thoughts?
Obviously it's still the certificate issue. Try using the latest CA certificates extracted from Mozilla. Simply download it, place it somewhere or replace your current cacert.perm, add the path to your certificate to openssl.cafile and curl.cainfo in your php.ini, and then try again. You might want to comment openssl.capath for now.
You can read more about issues related to CA certificate in PHPMailer Troubleshooting Wiki.
Update for 02/20/2018:
The curl.cainfo and openssl.cafile paths looks fine, assuming that is the correct path to the cacert.pem you downloaded. However your ini_cafile is empty when you run openssl_get_cert_locations(). It should reflect whatever you set in your openssl.cafile. You will need to restart your web server (Apache/nginx) after making changes to your php.ini to take effect. After restarting check the openssl.cafile value by running phpinfo(), and make sure it is correct.
I'm not sure why the default cert directory is like that. Maybe a previous installation of Open SSL? Either way, it's an non-existent default path for me as well but it doesn't matter since my ini_cafile shows the same value I defined in openssl.cafile. openssl_get_cert_locations() shows the list of places it will be looking for the certificates, so if the correct one is among the them, I think it should be fine.
I have this PHP code using the PHPMailer library
$email = new PHPMailer();
$email->IsSMTP();
$email->SMTPAuth = $Email_SMTPAuth;
$email->Host = $Email_Host;
$email->Port = $Email_Port;
$email->Username = $Email_Username;
$email->Password = $Email_Password;
$email->setFrom($result["emailfrom"], $result["fromname"]);
$email->Subject = stripslashes($result["subject"]);
$email->Body = stripslashes($result["message"]);
$email->AddAddress("email#domain.com");
if(!$email->Send()) {
echo $email->ErrorInfo;
} else {
echo 'sent';
}
When it fails to send, it show the error message:
The following From address failed: *EMAIL_ADDRESS_HERE* : Called Mail() without being connected
I believe it can be something to do with your host and port configuration, PHP Mailer might not be able to connect to your server with the settings you provided, thus giving you this error. Try checking again the configuration you set up, the host, port and username with your host and see if everything's all right.
Here is something similar to the error you're getting. Hope it helps :)
It happens frequently to me... when I forget to ask the provider to open a port to the host.
I have several sites hosted by a provider, and a DEM application running on the server. Depending on the provider, the server can be secured so that you are not allowed to connect freely to any SMTP host/port, but you have to be enabled to.
I am trying to setup a php page to automatically send a verification email. I would like to use the gmail smtp servers, and everywhere I've looked suggests to use PHPMailer. I installed it and used the following example code:
ini_set('display_errors', 1);
error_reporting(E_ALL);
require_once ("incl\PHPMailer\PHPMailerAutoload.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "myemail#gmail.com";
$mail->Password = "mypassword";
$mail->SetFrom('myemail#gmail.com','Me');
$mail->AddAddress("ToAddress#gmail.com");
$mail->Subject = "Verify your email";
$mail->Body = "Thank you for signing up. Please verify your email using the link below:";
$mail->IsHTML (true);
if($mail->Send()){
echo "Success";
}else{
echo "Error";
}
When trying to access the page via Firefox, the page will load for a few minutes, then give this error:
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
The server is Windows Server 2008 R2 Standard running IIS 7.5 and PHP Version 5.5.8. I can access all other pages without issues, but trying to call $mail->Send() seems to be timing out or something. I know this because I commented every line and slowly added pieces back in and $mail->Send() is the line that causes the behavior.
My Google abilities are failing me here as I simply cannot figure out how to make this work. Any ideas on what might be wrong?
Update
I opened the server log then tried loading the page again, but no new errors were added to the log. However, I noticed the following errors from today in System32\LogFiles\httperr1.log
2014-10-27 06:29:21 1.161.23.122 3148 212.83.145.123 80 HTTP/1.0 CONNECT mx2.mail2000.com.tw:25 400 - URL -
2014-10-27 10:10:12 95.183.244.244 33553 212.83.145.123 80 HTTP/1.1 GET / 400 - Hostname -
2014-10-27 11:25:25 207.38.185.197 51157 212.83.145.123 80 HTTP/1.1 GET /tmUnblock.cgi 400 - Hostname -
2014-10-27 12:46:21 1.168.221.158 7952 212.83.145.123 80 - - - - - Timer_ConnectionIdle -
UPDATE 2
I am positive that my gmail account details are correct and have tested sending from it using Thunderbird on the server. When trying to sent without secured methods, as suggested in this comment I get this error:
MAIL FROM command failed,550,5.7.3 Requested action aborted; user not authenticated
My PHP Mailer version is 5.2.9 and I've now also tried the following:
Using \\ in file paths instead of \
No change
Including class.phpmailer.php instead of PHPMailerAutoload.php
Fatal error: Class 'SMTP' not found in C:\inetpub\wwwroot\incl\PHPMailer\class.phpmailer.php on line 1195
Using ssl over port 465
SMTP connect() failed
Sending with a hotmail address over port 25 with $mail->SMTPAuth = false;
MAIL FROM command failed,550,5.7.3 Requested action aborted; user not authenticated
Update 3
After reloading the problem page, I checked through the Event Viewer and saw a new entry in Windows Logs -> System:
PHP Error : syntax error, unexpected BOOL_TRUE in C:\PHP\php.ini on line 101
That line is:
php_flag display_errors on
Looks like you're dealing with bunch of issues and here is a checklist: you're having issues with ssl, the actual mail software and credentials. It became an issue of 3 from one main issue and I'm guessing you don't either have your credentials typed in correctly or your open ssl isn't setup and you're also having issues using the mail software.
535 535 5.7.3 Authentication Unsuccessful means auth is unsuccessful, check your credentials username and password.
550 error code, it means that the receiving system could not deliver your email to the user to whom it was addressed because the mailbox is unavailable.
There are plenty of other solutions to resolve your issue. Why don't you try something more simple instead of using the autoload PHPMailerAutoload.php. Create a new file and place the code below, create a message body (test_message.html) and call it from the browser to test gmail smtp with the gmail credentials. This is a snippet from PHPMailer on how to use it with gmail smtp and it shouldn't go wrong if you have everything filled in correctly.
<?php
require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = file_get_contents('test_message.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "yourusername#gmail.com"; // GMAIL username
$mail->Password = "yourpassword"; // GMAIL password
$mail->SetFrom('name#yourdomain.com', 'First Last');
$mail->AddReplyTo("name#yourdomain.com","First Last");
$mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "whoto#otherdomain.com";
$mail->AddAddress($address, "John Doe");
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
If you're getting user auth error, then your credentials aren't typed in
correctly. If that's not the issue, you'll get an ssl error if you're not using the right port.
If there are software issues with include, you should try something better.
I was debating this morning if I should should PHPMailer, ended up using Swiftmailer which worked right after I installed it with PHPComposer.
My Internal mail server is extremely picky and has ton of firewall settings and rules on hardware and software level and I was surprised it didn't give me any problems; the emails were being sent right away without any problems on port 587.
require_once 'vendor/swiftmailer/swiftmailer/lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('mail.hellog***.com', 587)
->setUsername('apache#hellog***.com')
->setPassword('apa******')
;
This is what you need for gmail:
$transporter = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
->setUsername($this->username)
->setPassword($this->password);
$this->mailer = Swift_Mailer::newInstance($transporter);
If none of what you like, you can try phpgmailer:
https://github.com/GregDracoulis/LectureBank/tree/master/phpgmailer
here is an example on how to use it:
http://www.vulgarisoverip.com/2006/10/13/update-send-email-with-php-and-gmail-hosted-for-your-domain/
this class is dedicated for gmail use.
If all your problems and issues relate to openSSL, you should follow the steps below:
1. Make sure the OpenSSL module DLL file is included in the PHP installation:
C:\user>dir \local\php\ext\php_openssl.dll
Directory of C:\local\php\ext
php_openssl.dll
2. Create the PHP configuration file, \local\php\php.ini, if it does not exist:
C:\user>copy \local\php\php.ini-production \local\php\php.ini
1 file(s) copied.
3. Enable the OpenSSL module by editing the configuration file with a text editor. You need to remove the comment maker (;) on two configuration lines:
...
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "ext"
...
extension=php_openssl.dll
...
That’s it. You should be all set setting up openSSL on your Windows IIS WebServer. Follow these options and steps, it could be your issue.
This problem is slashes ( \ )
Edit
require_once ("incl\\PHPMailer\\PHPMailerAutoload.php");
I have tried with you code, and i have only changed this line :
require_once ("incl\PHPMailer\PHPMailerAutoload.php");
by this one :
require_once ("incl\PHPMailer\class.phpmailer.php");
And it was worked successfully.
Also you should keep attention about your PHPMailer version and your PHP version.
Have you tried to send an email with not secured method ?
Are you sure that your google credentials are valid ?
UPDATED
From the command line of your server, what is the output of this command and how much time that it takes to respond
telnet smtp.gmail.com 587
I wonder if you are running into the same issue that this question ran into. Google actively frowns on people using Gmail as their own personal SMTP server.
http://www.labnol.org/internet/email/gmail-daily-limit-sending-bulk-email/2191/
Google also limits the number of email messages that you can send through your Gmail account in a day. If you exceed the daily quota, Google may temporarily disable your Gmail account without any warnings and you may have to wait for up to 24 hours before you can regain access to your Gmail mailbox.
I could see an error like that potentially producing a 500 error.
From the comments to the question, it seems pretty clear that this issue is OpenSSL related.
You mentioned that you already have extension=php_openssl.dll uncommented, but phpinfo() does show it not beeing loaded.
Some thoughts:
Have you restarted the webserver, after uncommenting the openssl php module in your php.ini?
This is the really obvious one, but still worth mentioning. The php.ini is loaded on start-up, and not doing a service restart is simply a common mistake.
Check the value of Loaded Configuration File in phpinfo()
If this is not the same location than the php.ini which you have edited, it also becomes clear why it has not been loaded. Also following lines from phpinfo() might be worth checking.
Configuration File (php.ini) Path
Loaded Configuration File
Scan this dir for additional .ini files
There are other things too which can be done like uninstalling and reinstalling OpenSSL, but it might be good to check these more obvious things first.
Further thoughts:
Checking the error logs
For php the path can (again) be found in your phpinfo(). Look for the value of error_log and check the latest entries, right after you tried to reload your page.
Also you may wanna check the log files of IIS. If you don't know the path look in the IIS Manager, select the computer on the left pane, and in the middle pane, go under "logging" in the IIS area. Usually these will point to something like C:\inetpub\logs\LogFiles or C:\Windows\System32\LogFiles with a subfolder like W3SVC[x] where [x] is the website ID. (Will be just 1 if you only have one page, otherwise check the top level websites folder in IIS Manager, view the lists of sites in the right hand pane, it's the App ID)
Setting Up and Configuring IIS
Start by going to the ServerManager on you Server. Most often this is the server you’ll be running your php website on. Go to Add features in the Features summary section. Check SMTP Services in the Add Features Wizard and hit install. Now wait for the installation to finish. Open IIS6 (or IIS7) Manager under Administrative Tools -> Internet Information Services 6.0 in the Start Menu, the configuration of SMTP makes use of the management console from IIS6. Under [SMTP Virtual Server], click your right mouse button and select properties from the context menu. Go to the Access Tab and hit the Relay button.Add a new entry to the list by clicking the Add button and enter 127.0.0.1 (or your web server's IP) in the single computer entry field. Hit Ok two times to apply the new settings.
Configuring Php
To make Php send emails you need to make some configurations. Basically there are two options.
In case you’re only going to use the SMTP server in a single project and do not want it to interfere with other projects, you can set the configuration from within your php code by adding the following lines anywhere before sending the email:
ini_set('SMTP','localhost' );
ini_set('sendmail_from', 'administrator#YourWebsite.com');
Another way, to make global use of these settings, add the next lines to your php.ini file.
[mail function]
SMTP = localhost
sendmail_from = me#example.com
Make sure you restart your server after making these changes, to be sure they’re loaded.
This solution is provided here http://geekswithblogs.net/tkokke/archive/2009/05/31/sending-email-from-php-on-windows-using-iis.aspx on how to set up IIS and php and was provided as answer to this question 500 error when trying to use the MAIL function
Try to use SSL encryption with a port 465:
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
Warning: require_once(mailer/PHPMailerAutoload.php): failed to open
stream: No such file or directory in....
This is the way I had my file routed
Before:
require_once "mailer/PHPMailerAutoload.php";
After:
require_once "../mailer/PHPMailerAutoload.php";
...Same process you would normally do to link an img as background using css.
I can't figure for the life of me why exactly is it failing.. this is the exact error I am getting:
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection
could not be established with host smtp.gmail.com [Connection refused #111]' in
/home/content/38/6896038/html/test/lib/classes/Swift/Transport/StreamBuffer.php:259
Stack trace: #0
/home/content/38/6896038/html/test/lib/classes/Swift/Transport/StreamBuffer.php(64):
Swift_Transport_StreamBuffer->_establishSocketConnection() #1 /home/content/38/6896038/html/test/lib/classes/Swift/Transport/AbstractSmtpTransport.php(115): Swift_Transport_StreamBuffer->initialize(Array) #2 /home/content/38/6896038/html/test/lib/classes/Swift/Mailer.php(80): Swift_Transport_AbstractSmtpTransport->start() #3 /home/content/38/6896038/html/test/contact.php(55): Swift_Mailer->send(Object(Swift_Message)) #4 {main} thrown in /home/content/38/6896038/html/test/lib/classes/Swift/Transport/StreamBuffer.php on line 259
And the code Im using is what I've gotten from the tutorial and reading on here examples, here it is:
require_once 'lib/swift_required.php';
$transport = Swift_MailTransport::newInstance();
// Create the Transport the call setUsername() and setPassword()
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
->setUsername('email#googleappsdomain.com')
->setPassword('xxx')
;
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
$nombre = $_POST['name'];
$apellido = $_POST['apellido'];
$email = $_POST['email'];
$telefono = $_POST['telefono'];
$title = $_POST['jobtitle'];
// Create the message
$message = Swift_Message::newInstance()
// Give the message a subject
->setSubject('Nuevo applicante para: ' . $title)
// Set the From address with an associative array
->setFrom(array('no-reply#topytop.com.pe' => 'no-reply'))
// Set the To addresses with an associative array
->setTo('email#thisemail.com')
// Give it a body
->setBody('<html>
<head></head>
<body>
<table>
<tr>
<td>Nombre:</td><td>' . $nombre . ' ' . $apellido .'</td>
</tr>
<tr>
<td>Email:</td><td>' . $email . '</td>
</tr>
<tr>
<td>Telefono:</td><td>'. $telefono .'</td>
</tr>
</table>
</body>
</html>', 'text/html')
// Optionally add any attachments
->attach(Swift_Attachment::fromPath($_FILES["file"]["tmp_name"])->setFilename($_FILES['file']['name']));
// Send the message
$result = $mailer->send($message);
any help is greatly appreciated, I've done my reading and searching and cannot find a solution to this :(
EDIT: Apparently it's an issue with gmail, I changed to a different smtp and it worked.. :S
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.gmail.com [Connection refused #111]
Connection refused is a very explicit and clear error message. It means that the socket connection could not be established because the remote end actively refused to connect.
It's very unlikely that Google is blocking the connection.
It's very likely that your web hosting provider has firewall settings that block outgoing connections on port 465, or that they are blocking SMTP to Gmail. 465 is the "wrong" port for secure SMTP, though it is often used, and Gmail does listen there. Try port 587 instead. If the connection is still refused, call your host and ask them what's up.
remove from your config.yml
spool: { type: memory }
Then you will be to add try catch like this
try{
$mailer = $this->getMailer();
$response = $this->getMailer()->send($message);
}catch(\Swift_TransportException $e){
$response = $e->getMessage() ;
}
I had the same issue when I was using Godaddy web hosting and solved this by editing my .env file as,
MAIL_DRIVER=smtp
MAIL_HOST=XXXX.XXXX.in
MAIL_PORT=587
MAIL_USERNAME=dexxxxx
MAIL_PASSWORD=XXXXXXXX
MAIL_ENCRYPTION=tls
Where MAIL_HOST is your domain name from Godaddy, MAIL_USERNAME is your user name from Godaddy and MAIL_PASSWORD is your password from Godaddy.
I hope this may help you.
tcp:465 was blocked. Try to add a new firewall rules and add a rule port 465. or check 587 and change the encryption to tls.
My solution was to change:
'driver' => 'smtp',
to
'driver' => 'mail',
In app/config/mail
Hope that helps
In v 5.8.38, I set the env file as the following:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=mygmail#gmail.com
MAIL_PASSWORD=difficultCombination
MAIL_ENCRYPTION=ssl
MAIL_FROM_NAME=myWebappName
After doing php artisan config:clear, it worked well on a shard server.
I had the same problem for a while, replacing: smtp.gmail.com with 173.194.65.108 actually worked for me!
In my case, I was using Laravel 5 and I had forgotten to change the mail globals in the .env file that is located in your directory root folder (these variables override your mail configuration)
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=yourmail#gmail.com
MAIL_PASSWORD=yourpassword
by default, the mailhost is:
MAIL_HOST=mailtraper.io
I was getting the same error but that worked for me.
I had the same issue and i manage to fix it by disabling my AVAST Anti Virus. As well as my AVAST extension in the browser. Antivirus sometimes blocks your application. :) I hope it helps to anyone.
firstly,check for gmail SMTP server . you should have to allow access for less secured apps without allowing swift mailer is not possible.for this login in your email account first then go into privacy settings and then click on sign and security then click on apps without access and then make on to less secure apps option then try mailer again, it will work then.
In my case, I had trouble with GoDaddy and SSL encryption.
Setting the encryption to Null and Port to 80 (Or any supportive port) did the job.
If you have hosted your website already it advisable to use the email or create an offical mail to send the email
Let say your url is www.example.com. Then go to the cpanel create an email which will be send#example.com. Then request for the setting of the email. Change the email address to send#example.com. Then change your smtp which will be mail.example.com. The ssl will remain 465
I just had this issue and solved it by editing mail.php under config folder. Usually when using shared hosting, they hosting company allows you to create an email such as
XXXX#yourdomainname.com
. So go to email settings under you shared hosting cpanel and add new email. Take that email and password and set it in the
mail.php.
It should work!
Im using the following code to send a message:
try
{
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
$smtp =& new Swift_Connection_SMTP("mail.somedomain.net", 587);
$smtp->setUsername("username");
$smtp->setpassword("password");
$swift =& new Swift($smtp);
//Create the sender from the details we've been given
$sender =& new Swift_Address($email, $name);
$message =& new Swift_Message("message title");
$message->attach(new Swift_Message_Part("Hello"));
//Try sending the email
$sent = $swift->send($message, "$myEmail", $sender);
//Disconnect from SMTP, we're done
$swift->disconnect();
if($sent)
{
print 'sent';
}
else
{
print 'not sent';
}
}
catch (Exception $e)
{
echo"$e";
}
The issue is that it is working fine on my local server (which my xampp server) but not working when the file is uploaded on the real server.
It throwing this error:
'The SMTP connection failed to start [mail.somedomain.net:587]: fsockopen returned Error Number 110 and Error String 'Connection timed out''
Please what should I do to correct this error. Thanks for reading
Make sure that the smtp server domain is valid. Trying pinging it to confirm a response. You may also try trace route to see if any of the switches are returning slow responses.
$smtp =& new Swift_Connection_SMTP("mail.somedomain.net", 587);
is that '587' the port number to connect to? Any reason you're trying that instead of the normal port 25? Port 587 (submission) is normally used for local users to send mail. Once you're running this script on your remote web server, it's no longer "local", and is most likely firewalled off (or the mail server's not listening to that port on external interfaces).
Try switching to port 25 and see if that helps any.
update:
Connection refused is better than "connection timed out". It means at least that the initial data packet got somewhere and was actively refused. Timed out means things just got dropped silently somewhere en-route.
max_execution_time would only come into play if the php script itself went over the max time. If that was the case, you wouldn't be getting a swiftmailer error, because the script would have simply terminated.
Is your webserver running sendmail? Change the connection host to 'localhost' and see if that helps. If you just want to send an email, then that should work. The only reason you might want to connect to a remote SMTP server is for the From: headers to be correctly set and not be possibly flagged as SPAM on the receving end.