In php.ini I set:
SMTP = smtp.gmail.com
smtp_port = 465
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = mygmail#gmail.com
In my sendmail.ini:
smtp_server=smtp.gmail.com
smtp_ssl=ssl
auth_username=mygmail#gmail.com
auth_password=mygmail password
In my error log:
13/05/18 23:33:30 : Socket Error # 10060<EOL>Connection timed out.
The email actually sent twice, but 99% of the time, I get the same error as above. I disabled my router's SPI, and my computer's firewall. Any ideas?
Most local boxes with Windows don't come with a SMTP server. You could use an external SMTP server and configure it in your php.ini file, but SMTP authentication is not possible.
I recommend you to use PHPMailer, is a simple and flexible PHP Class, that can use a SMTP server with authentication. It is also more secure than using bundled PHP mail() function.
http://phpmailer.worxware.com/
Related
I need to send mail from PHP code, I am using XAMPP (windows) for PHP. I use mail() like this:
Here is my code in php.ini:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from =email#gmail.com
My PHP code:
if(mail("email#gmail.com",$subject,$message))
{
echo "mail sent";
}
else
{
echo "error";
}
I get the message 'mail sent' but did not receive an email. What am I doing wrong?
Use smtp.gmail.com as smtp host and set port to 587, you will also need to set up authentication and for that reason I'd suggest using something a bit more advanced than the native mail function; examples are PEAR's Mail package, SwiftMailer or PHPMailer.
You are using gmail to send email then you should configure gmail POP settings...
In general you need to have SMTP Server configured on server.
You've set up this smtp server: "localhost:25". Do you have some SMTP-server running on this port on your local machine?
If you want to send emails from local machine you should either setup some SMTP-server locally (but this is not simple) or use some remote SMTP-gateway. Google for it.
Upd. Anyway this is duplicate
How to configure XAMPP to send mail from localhost?
I need some help. I am trying to send an email from a php script. My environment comprises of the following:
Operating System: Windows 8
XAMPP version: 1.8.2
php version: 5.4.19
I have the following php script:
<?php
mail('sugar.donkey#gmail.com','Helo','This is a test','From:salt#goodness.com');
?>
The following configuration on send mail configuration file:
smtp_server=smtp.gmail.com
; smtp port (normally 25)
smtp_port=465
auth_username=sugar.donkey+gmail.com
auth_password=[MYPASSWORDHERE]
The configurations on php.ini:
[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
; SMTP = smtp.gmail.com
; smtp_port = 465
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = postmaster#localhost
I dont get error when I run the php script, but I also dont seem to receive an email. Where am I going wrong ?
I am not sure what os you are running on your webserver, however;
Most Linux installations have sendmail preinstalled, there is always a hassle of setting up SPF/PTR records, to ensure that the email sent by your PHP script is not flagged as spam. A SMTP client called MSMTP can be used to send emails using third-party SMTP servers, this can also be used by PHP's mail() in the place of sendmail.
I hope this helps
https://www.digitalocean.com/community/articles/how-to-use-gmail-or-yahoo-with-php-mail-function
Also for localhost testing, check this out.
http://blogs.bigfish.tv/adam/2009/12/03/setup-a-testing-mail-server-using-php-on-mac-os-x/
Even I am trying to get this configuration work :)
in your case i believe you need to comment out in php.ini
the configuration should be
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = smtp.gmail.com
smtp_port = 465
; For Win32 only.
http://php.net/sendmail-from
sendmail_from = postmaster#localhost
Thank you
Here's what's in my php.ini file:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
Is it possible to simply change localhost to smtp.live.com and change the port (smtp_port) to point to a different port (specifically, 567, as required by Microsoft) in order to send email to a Microsoft Live email address via PHP? I tried the normal mail() route, but I never received the email from the script, and can only assume it has to do with SMTP authentication. I don't have very much experience with PHP.
No, that won't work. smtp.live.com requires authentication, and the PHP mail() command does not support authentication. As Pascamel suggested, you should use a library that supports sending mail through a remote SMTP server using authentication. phpmailer is very good.
Have a look at PHPMailer : https://github.com/PHPMailer/PHPMailer
I'm using it to send emails through a GMail account, settings are pretty easy!
This way you won't have to update your php.ini
in php.ini you can change smtp server to different server ONLY for WINDOWS machines.
You can't do it for unix machines. it just ignores even if you set smtp = yourserver.
I want to send an e-mail using a php code,I am using wampserver.
an error appear :
mail() [function.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 C:\wamp\www\Newsletter1\index.php on line 29
My file php.ini
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = myEmail#gmail.com
Is there any more configuration to do?
Update
I'am using the mail function to send a newsletter to subscriber and I am testing now locally then I will test the code on production environment
You need a SMTP mailserver daemon running on localhost. If you are using a unix host and you don't want to setup a full SMTP agent, try removing the SMTP config part, thus directly using sendmail. From the docs:
The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket (which can either on the localhost or a remote machine).
Check your Firewall maybe php is blocked to connect server. Or try change localhost to 127.0.0.1 .
You need either smtp server on your server or you need to connect to external smtp server to send email.
to connect via external smtp you can use
http://pear.php.net/package/Mail
here is answer to your question as well with an example of how to use it.
smtp configuration for php mail
If you are working on a test environement look at this link: http://www.toolheap.com/test-mail-server-tool/
This little app will simulate an SMTP server on your computer.
It gives you some hint on how to test and debug mail features for your php applications.
I have encountered an error:
Warning: mail() [function.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 C:\works\test\registration-code3.php on line 56
Here is my php.ini:
define_syslog_variables = Off
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = postmaster#localhost
How can I fix this?
Based on what you've shown us, particularly this bit:
C:\works\test\registration-code3.php
Leads me to believe your testing some script on your local system. If this is so and you haven't installed and set up a mail server, then of course its not going to work. You require a MTA to actually send the email, PHP just hands off to it.
If you've simply installed XAMPP then you don't have a working MTA to send through without some real work ahead of you.
If you must send email from your dev machine in this fashion, I recommend picking and using a script like Swiftmailer which will allow you to easily use a mail server hosted elsewhere - like your ISP or even google.
It looks like your Windows machine don't have SMTP server on the port 25. I am guessing that it is your development machine. Instead editing your ini file you can try some other SMTP servers, for instance, the one your ISP provided you with.
Try to add the following code to the top of email script:
ini_set("SMTP","mail.domain.com");
ini_set("smtp_port","25");
ini_set('sendmail_from', 'Email#domain.com');