-
January 2nd, 2007, 12:13 PM
#1
sending emails through PHP
I have tried to send emails through both the mail(..) function and through the phpmailer but fails on both the accounts.
I can provide the code if that is desired. I have set the SMTP while using the mail(..) function through the ini_set("SMTP", ...) and also with the phpmailer functions but I get the following errors:
Error 1:
Code:
Debug Warning: C:\Program Files\Pcounter Web Report\www\libraries\class.phpmailer.php line 1255 - mail(): Failed to connect to mailserver at "smtp.wlink.com.np" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
E]
Error 2:
Code:
Debug Warning: C:\Program Files\Pcounter Web Report\www\libraries\class.smtp.php line 177 - fsockopen(): unable to connect to smtp.wlink.com.np:25
smtp.wlink.com.np is my ISP's SMTP address and the port used is the default: 25.
However when I send the mail through the MS-OUTLOOK I can easily send mails. However with the MS-OUTLOOK I have an account with the ISP and I have to use a password for it.
Is my ISP blocking so that I cannot send mails programatically? What could be the problem? How do I supply the password when sending the mails through PHP programatically? The sender email address is the same address that I have in the MS-OUTLOOK and this address was provided to me by the ISP company?
Thanx in advance.
If there is no love sun won't shine
-
January 2nd, 2007, 01:19 PM
#2
Re: sending emails through PHP
It may be that authentication is required for SMTP. In order to use the mail() function with PHP, it must be a non-authenticated SMTP server.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
January 2nd, 2007, 11:58 PM
#3
Re: sending emails through PHP
Peej is right, you probably need to authenticate.
You could search for such a function, but it would be fairly easy to write your own, for example:
PHP Code:
function authMail($server,$user,$pass,$to,$from,$body,$headers) {
$con = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
socket_connect($con,$server,25);
socket_send($con,"HELO",4);
socket_send($con,$user,strlen($user));
.....
}
Obviously that's not the whole function, besides connection error catching you would need to search google for the RFC SMTP commands for sending an e-mail (which i do not know off the top of my head), but this should start you off. This is not easy for a PHP beginner, which is why i recommend all beginners start programming PHP on linux as most things just work (kind of backwards from everything else) and sendmail (or other linux mail exchangers) are much more reliable, and much faster then using SMTP for sending mail.
Your basically required to re-write the built in mail function, however im almost positive that if you spent 10-15 minutes searching on google you could find someone who has already solved your problem, mail and PHP go together like peas and carrots jenny.
Hope this helps,
Dave
Last edited by Zetas; January 3rd, 2007 at 12:01 AM.
-
January 3rd, 2007, 06:30 AM
#4
Re: sending emails through PHP
Thank you both of you for your answers:
I have further information:
I contacted my ISP and have confirmed that it is not a Server which requires Authentication. The authentication is only for the POP3. This is also reflected by the error returned. The error returned doesn't state authentication problem but states that the connection to the SMTP host could not be made.
I debugged the phpmailer class and arrived at this function:
fsockopen. This function returns false.
The $errno = 10053 and the $errstr = "An established connection was aborted by a software in your host machine"
"software in your host machine is misleading. Does it mean some software in my computer or the SMTP server?
I could not get more information in the net about errno 10053. Hope you can point me to a list of fsockopen error codes and matching error text.
I am using XP 2002 Professional. I even disabled the "Windows firewall" but the problem persists. Another question I have is "Do I have to restart my machine after setting the Windows Firewall off?
Please any further help will be very much appreciated.
If there is no love sun won't shine
-
January 3rd, 2007, 11:59 AM
#5
Re: sending emails through PHP
No, you should not have to reboot after disabling the Windows firewall. I would also suggest looking at other spyware and antivirus applications that you have running on your machine. Sometimes they have built in firewalls that could be blocking this.
Now, it says the host machine is blocking. As you know, the host machine is the one running the web server. If you are doing this remotely, you might want to contact your web host.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
January 3rd, 2007, 02:16 PM
#6
Re: sending emails through PHP
Yea, sorry im not sure what to tell you. This is one of the reasons i stay away from windows, the networking profile is very difficult to debug many things could be blocking or fudging up your connection.
Why are you using fsockopen() in addition to the built in mail() function?
Can you post the entire mailer function? I think thats the only way anyone will be able to help you.
-Dave
-
January 6th, 2007, 10:59 AM
#7
Re: sending emails through PHP
Thank you all of you. The problem has been solved. The problem was as anticipated by PeejAvery. My free perpetual edition of McAfee virus was blocking the connection. Only disabling it was not enough. I had to completely uninstall it. Maybe that's a defect to have a free edition and they somehow make you buy the commercial product.
To test the connection of the SMTP server someone suggessted me to use the "telnet" program. The function is very useful in case someone needs in future. The telnet program was also failing to connect to the SMTP server. Someone at my ISP told be to uninstall my Antivirus program and I did the same. Now the "telnet" succeeds. The PHP's built-in mail(...) function succeeds and also the phpmailer classes's "send" function succeeds. The email is also received at the other end verified this by sending the mail to myself.
Gosh it took me 3 days entirely to have the problem resolved.
If there is no love sun won't shine
-
January 6th, 2007, 12:55 PM
#8
Re: sending emails through PHP
Glad you solved it. Good luck with the rest.
I would highly recommend staying away from Norton/Symantec or Mcafee. Both are not what people think. They really are memory wasters. On my PCs at work, I use Grisoft AVG. There is both a commercial version and free version. Also, when it comes to spyware on a PC, Spyware Terminator is the way to go. It is also free for non-profit organizations.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
January 7th, 2007, 07:40 AM
#9
Re: sending emails through PHP
Originally Posted by PeejAvery
Glad you solved it. Good luck with the rest.
I would highly recommend staying away from Norton/Symantec or Mcafee. Both are not what people think. They really are memory wasters. On my PCs at work, I use Grisoft AVG. There is both a commercial version and free version. Also, when it comes to spyware on a PC, Spyware Terminator is the way to go. It is also free for non-profit organizations.
Anti-virus programs are dreadful things. I have never installed one and never intend to. The best defence against virus' is more often than not, yours truly.
-
January 7th, 2007, 08:48 AM
#10
Re: sending emails through PHP
Originally Posted by visualAd
Anti-virus programs are dreadful things. I have never installed one and never intend to. The best defence against virus' is more often than not, yours truly.
Also, a very smart thing to do, is have an administrative user, and a restricted user. When browsing the internet, use the restricted user.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
January 7th, 2007, 10:15 AM
#11
Re: sending emails through PHP
Originally Posted by PeejAvery
Also, a very smart thing to do, is have an administrative user, and a restricted user. When browsing the internet, use the restricted user.
Yes. I use a restricted account for everything I can and get I am most put out when a program such as a game (requires) admin privileges, just to run.
I heard that browsing with a restricted account, using a non IE browser and sitting behind a router with a packet filtering firewall. You can reduce the risk of becoming a victim by nearly 80%. The other 20% is just being vigilant.
-
January 7th, 2007, 04:00 PM
#12
Re: sending emails through PHP
Well, I have a Mac so IE is out of the question. Plus, I just don't like IE. On my PCs I use Firefox.
Okay, sorry for the chat. I am back on subject.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|