Sendmail Wamp Php - php

I have spent all the morning searching this on internet trying to find a solution about this.
I have installed wamp server on Windows 8.1 and i'm trying to send some mails with sendmail (http://glob.com.au/sendmail/) and my gmail account
When i configure sendmail to use port nº 465 I always get this error: Socket Error # 10060Connection timed out
If i try to use port nº 587 i get this line on error log: Connection Closed Gracefully. But no email is sent.
This is my sendmail.ini file
[sendmail]
smtp_server=smtp.gmail.com
;I tried both: 587, 465
smtp_port=587
; I tried: "blank, auto ssl, tls, none"
smtp_ssl=
error_logfile=error.log
debug_logfile=debug.log
auth_username=myaccoun#gmail.com
auth_password=mypass
hostname=localhost
And this is php.ini file
[mail function]
smtp_port = 465
sendmail_path="C:\wamp\sendmail\sendmail.exe -t"
mail.add_x_header = On
ssl_module is active on apache, and php uses php_open_ssl and php_socket extension.
Also i tried to use stunnel whitout any success
EDIT 27/01/2014
I set smtp_port = 465 and smtp_ssl=ssl on sendmail.ini. Also, I set that sendmail.exe has to run as a Windows XP SP3 programs. After doing that, when I run sendmail.exe on windows console, it sends the email correctly. However, when wamp tries to send mails i get this error on sendmail's error logs.: Socket Error # 10060Connection timed out.
This is the code I'm using to test sendmail:
<?php
$email = "mymail#gmail.com";
$to = "mymail#gmail.com";
$subject = "Hi!";
$body = "Hi,How are you?";
$headers = 'From: ' .$email . "\r\n".'Reply-To: ' . $email. "\r\n".'X-Mailer: PHP/' . phpversion();
if (mail($to, $subject, $body, $headers)) echo("<p>Email successfully sent</p>");
else echo("<p>Email delivery failed</p>");
?>

Finally I found the answer.
The problem is that sendmail has to be run as an administrator. This is the solution to help any one on my situation.
Right click on sendmail.exe
Properties
Compatibility
Change the configuration for all users
Execute as Windows XP SP 3
Execute as adminitrator
And save :D
2 days lost in this nonsense :(

As an extension to the accepted answer:
If you are running the send mail function in PHP, a dialog may come up to ask you to run the 'send mail' app as admin. Upon cliking 'Yes' it will show a command prompt dialog and nothing will happen and you page will hang until the command prompt is closed. The mail function will even return "True", but in reality no message was sent.
To solve this issue, do the instructions same as the accepted answer and ALSO run the server (or IDE) as admin, by either:
1) Right clicking the program (e.g. server, ide, command prompt) and clicking "Run as Administer"
2) OR Right click program> properties> compatiblity> Tick execute as admin
For instance if your using the PHP in built server, run the command prompt as admin and start the server as normal using
C:\wamp\bin\php\php5.5.12\php.exe -S localhost:80 -t C:\Users\path\to\rootFolder
Of course change the file paths to suit your needs.
Hope this helps someone!!! Spent ages on this!

The problem is that sendmail has to be run as an administrator. This is the solution to help any one on my situation.
Right click on sendmail.exe
Properties
Compatibility
Change the configuration for all users
Execute as Windows XP SP 3
Execute as adminitrator
if you using gmail you need create new password "Your application-specific passwords"

On Windows 10, I found the only method that worked was to run the Compatibility Troubleshooter.
Right click on sendmail.exe
Click "Properties"
Select the Compatibility tab.
Click "Run Compatibility Troubleshooter".
Let windows fix it automatically.

Related

Sendmail : Connection closed gracefully

I am using wamp server on Windows with the sendmail program. I am trying to send an e-mail from my personal computer with my business email.
I configured the sendmail.ini
smtp_server=localhost
smtp_port=1055
default_domain=company.something
auth_username=mymail#company.something
auth_password= *****
I also changed the php.ini
SMTP = localhost
smtp_port = 1055
sendmail_path = "path\to\sendmail.exe"
And after reading others questions I used this trick
1º Right click on sendmail.exe
2º Properties
3º Compatibility
4º Change the configuration for all users
5º Execute as Windows XP SP 3
6º Execute as adminitrator
But still got the "Connection Closed Gracefully." error.
I am sure that my SMTP is correct because I use the same with Thunderbird and it run everyday since a year ago without any problem.
I am also sure that my configuration is well working because I tried to change the parameters to use a gmail account and it is working.
I just want to know, what this error mean ?

Sending mail from local apache server fails, no error message given

Foreword; I've looked through a lot of topics, done what they said, but nothing works for me - so I made this one.
So I'm using xampp/apache to send mail from a php file, but all I get is "Message delivery failed...".
Does anyone know what I'm doing wrong, or maybe how to display an error of whats going wrong because I don't get any errors.
Here is my code..
(I censored my email and pass for obvious reasons)
if (!mail("censored#gmail.com", "title", "blahblahblah", "From: me#hotmail.com")) {
die("<p>Message delivery failed...</p>") . mysqli_error();
}
?>
sendmail.ini:
smtp_server=smtp.gmail.com
smtp_port=465
auto = use SSL for port 465, otherwise try to use TLS
auth_username=censored#gmail.com
auth_password=censored
php.ini:
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
If any additional information is requested it will be from beyond this point.
Try allowing less secure apps to send you email using this link: https://www.google.com/settings/security/lesssecureapps
SElinux blocks sendmail from web server by default, change settings in SElinux as:
setsebool -P httpd_can_sendmail on

How do I test contact form in Windows XP using XAMPP through localhost?

I have coded a web site from scratch with XHTML, using Windows XP Pro, and this includes a contact form in PHP. The web site is in a XAMPP folder on the C drive and being run under localhost on my computer at home.
I want to test the form by sending an email test message from it to my live email address. I have tried this by changing the SMTP = localhost in the PHP .ini file to my ISP server address, activating the line,
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
and adding a semicolon to the beginning of the line below,
sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"
I have placed my live email address in the contact form code like so:
<?php
//send email
if(mail('my#emailaddress.net','Contact
form',$msg, 'From:postmaster#localhost')) {
?>
Then I tried another way by placing my email address under the if(POST) function instead:
<?php
if($_POST) {
$fName = $_POST['fName'];
$fEmail = $_POST['fEmail'];
$fComments = $_POST['fComments'];
$fCaptcha = $_POST['fCaptcha'];
$random_string = $_POST['random_string'];
$to = "myemailaddress#myisp.net";
?>
And changed the mail function lower down in the script accordingly:
<?php
//send email
mail($to, $fName, $fEmail, $fComments);
if(mail($to,'Contact form',$msg, 'From:postmaster#localhost')) {
header("Location: ../email-thankyou.htm");
?>
When I clicked on the submit button, it generated an error page from my ISP server the first time, and from the Firefox browser during later attempts, so something is happening, but in looking at my live email account there is no sign of my message arriving.
I also found that the form itself disappeared and I was left with just the background colour of the page, when clicking on the submit button when I tried the second method.
I have searched through Stack Overflow for similar queries, and tried a few suggestions without success.
I am using XAMPP version 3.1.0.3.1.0. Although I am conversant with XHTML coding, I am a complete novice with regards to PHP programming, as this project using PHP is my first effort to get to grips with it, and would really appreciate any help and advice given, particularly as to writing the mail($to, and if(mail($to, out correctly.
I have now found the answer to this question by downloading and installing smtp4dev 2009 on my C drive. With this little program in conjunction with XAMPP, I can now test my contact form and it receives the messages successfully. The only other thing I needed to to was to configure the XAMPP php ini file as follows:
[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = localhost
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = postmaster#localhost
; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program filesC:\xampp) fakemail and mailtodisk do not work correctly.
; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path.
; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
;sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder
;sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"
As far as the earlier problem of the form disappearing when clicking on the Send button, is concerned - part of the script was in the wrong place and after some trial and error in positioning it, this problem was solved.
You want to set up mercury or a local mail server to be able to do this. Mecury comes installed with xampp.
http://www.youtube.com/watch?v=VU4PT7xMSO0

Why is php mail not sent when I have true boolean value and seems to be OK

$res= mail('myemailaddress#live.com', 'Email verification ','This is my own text');
print $res;
I have tried to send mail to my email id. I have 1 on page. Looks like it's working but it really did not work.
php.ini:
define_syslog_variables = Off
[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = localhost
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = mymailaddressishere#live.in
; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program files\xampp-portable) fakemail and mailtodisk do not work correctly.
; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path.
; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
sendmail_path = "\"\xampp-portable\sendmail\sendmail.exe\" -t"
; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the \xampp-portable\mailoutput folder
sendmail_path = "\xampp-portable\mailtodisk\mailtodisk.exe"
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =
; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = Off
; Log all mail() calls including the full path of the script, line #, to address and headers
;mail.log = "\xampp-portable\php\logs\php_mail.log"
[SQL]
I want to know that how I can trace what happen to my code. If I need to do some settings in my local php server then tell me about them.
I am using xampp portable "Run as administrator".
There is a line in your file that says:
; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the \xampp-portable\mailoutput folder
sendmail_path = "\xampp-portable\mailtodisk\mailtodisk.exe"
In my XAMPP installation, I found that the comment was wrong. You actually have to uncomment the line if you want to use mailToDisk, and the mail is actually written to /tmp/mailoutput.
I can't use a comment system, so I can only post it here. but I think this is not the answer you are looking for.
XAMP might not be able to send email. Most localhost testing environment, such as xamp, or wamp are not able to send email. They need to be set up as mail server first. You could try setting them as mail server, but I think it's easier to just get a free hosting (with some "ugly" subdomain name), and put your script there and try to send mail.
I am going out on a limb by saying this: You don't have an SMTP server installed, let alone running. Just because your php.ini says mail() will use SMTP # localhost:25 doesn't really mean it is installed and running. The mail() function will return true even if it doesn't actually send the letter.
If you have installed an SMTP server (which doesn't come packaged as of now with XAMPP), and have it running, then I apologize. Please post which SMTP server you are using and your services list to ensure it is running. Then it will be easier to diagnose.
EDIT
Just tested on my computer without SMTP server being set up:
$a= #mail('sales#ellsworthpublishing.com', 'asdf', 'asdf');
if(!$a)
echo'False';
else
echo'True';
The output is True.

PHP mail() on Windows: no errors, the email isn't sent

I'm currently trying to debug an Elgg-based website (I didn't develop it) and I would like to send the emails directly from local development machine (WinXP). I'm running WAMP with Apache 2.2.11 and PHP 5.3.0
After some searching, the simplest solution that I've come across is using fake sendmail to forward it to my GMail/Google apps account via SMTP and let it do the sending. The problem is that I get no errors whatsoever, but the email isn't being sent.
Here's what I did:
Copied the sendmail.exe and sendmail.ini to a subfolder in WAMP
Configured it via sendmail.ini (the configuration settings are ok)
Edited php.ini to add the path to sendmail.exe
sendmail_path = "C:\Program Files\wamp\bin\sendmail\sendmail.exe -t"
Commented out the windows SMTP settings in php.ini
; SMTP = localhost
; smtp_port = 25
; sendmail_from = xxx#domain.com
; mail.force_extra_parameters =
The mail.log file shows the following:
mail() on [C:\Program Files\wamp\www\mail.php:9]: To: xxx --
Headers: From: xxx Reply-To: xxx X-Mailer: PHP/5.3.0
My guess is that the problem is that the default Windows option (to specify the server and not the sendmail utility) is not overriden. In phpinfo() I still get the SMTP -> localhost and smtp_port -> 25 options, even though I commented them.
If anyone managed to get this working, I'd really appreciate some help. In my opinion, using fake sendmail is a lot simpler than installing a mail server on your machine.
Thanks!
P.S. Please don't suggest PHPMailer and the like, because I have to use the mail() function. That's how Elgg works.
I've gotten it to work eventually. The problem was that PHP had a bug in parsing .ini files with spaces in the path (for sendmail). It was fixed in version 5.3.0, but the manual had no info on this.
So, yes, it is possible to use sendmail with PHP on Windows :D.
Thank you all for your time!
Make sure you have SMTP Service running on your local machine and that SMTP Port(25) is opened.
Have a check on the services (Run->services.msc) and look for Send Mail Transfer
If you cannot find SMTP on the services list, you must install it:
To add,
Run->appwiz.cpl->Add Remove Windows components->IIS->Details->SMTP
I am not sure if this helps or not, what i used to do in these scenarios was to setup , outlook on my machine and have it set to get emails from the pop every 5 mins or so, that way my ip/machine was authenticated against the pop and if i just set the :
SMTP = localhost
smtp_port = 25
in php.ini , the mail function worked fine. So in your case just set your outlook to work with a pop and use that smtp in php.ini and hopefully it should work. I havent tested this will GMail though.
P.S. Please don't suggest PHPMailer and the like, because I have to use the mail() function. That's how Elgg works.
...unless you're using a plugin that changes this behaviour:
http://community.elgg.org/pg/plugins/costelloc/read/16498/phpmailer

Categories