php mail() giving me a "no disk" error - php

Hey I am trying to send an email from a php script. When I try to do so, I get a pop up box that is titled "mailtodisk.exe - No Disk". In the body of the error message, it says, "There is no disk in the drive. Please insert a disk into drive \Device\Harddisk1\DR1".
I have tried to figure this out but to no avail. I am doing this from localhost.
Here is my script that is supposed to send the email:
<?php
$to = $_POST['email1'];
$subject = "Test mail";
$message = "I just sent you an email!";
$from = "ULSRL#louisiana.edu";
$headers = "From:" . $from;
if( mail($to, $subject, $message, $headers) )
{
echo ("Mail Sent.");
}
else
{
echo ("Mail could not be sent!");
}
?>
Any help is greatly appreciated! Thanks :)

I am guessing you are using XAMPP?
If so you will need to modify the php.ini located in your XAMPP installion, look for the following lines:
; 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:\mailtodisk\mailtodisk.exe"
mail cannot be delivered in PHP even SMTP server is running and PHP mail() returns true
This should also help:
http://blog.joergboesche.de/xampp-sendmail-php-mailversand-fuer-windows-konfigurieren#xampp_180_sendmail

You are trying this solution in Localhost. So you can get this error. Try in live work. You will definitely succeed.

For XAMPP, I have the same message it shows about 4 times providing options
{cancel}, {try again}, {continue}
No matter what I choose it replied 4 times and instead of showing the next page it showed the blank page.
My XAMPP version saves emails to the C:\xampp\mailoutput and this part was working.
What I did was: I commented out the following line is PHP.ini
;sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"
Now it does not save the files in C:\xampp\mailoutput
BUT it does not give me this annoying error and the next page loads fine.

Root cause of the problem is that mailtodisk.exe tries to reach non existing drive on your Windows machine, which cause this annoying message. This can be considered as a bug in mailtodisk actually, so you can simply don't use it as other replies here suggest.
This problem is caused usually because of USB sockets attached to your computer, for example for reading SD cards, which are currently empty.
If you prefer walking on the wild side, you can tweak your registry and suppress this message. See video demonstration here https://www.youtube.com/watch?v=Aj7-pLaAq2c

Related

PHP can send email from command line but not browser

I have a form set up at my homepage. When someone submits the form, it redirects them to a php script that sends me the form. The only issue is, the form won't send me anything when I use the browser. I have a script running on the same server that when I execute from the command line, sends an email immediately. When I go to the page in a browser, it gives a confirmation message, but won't send anything. What's happening? PHP is using MSMTP to send email if that helps. I believe apache is running as root (I know that's bad). How do I check?
Here's the code if anyone wants it:
<?php
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$from = "mailbot#prototypexenon.tech";
$to = "<MYEMAIL>";
$subject = "PHP Mail Test script";
$message = "This is a test to check the PHP Mail functionality";
$headers = "From:" . $from;
mail($to,$subject,$message, $headers);
echo "Test email sent";
?>
EDIT: Apparently new-server-owner was smart enough to not let apache run as root. All fixed now. Thanks #EdHeal
PHP running via the command line and PHP running via a web server can use totally different php.ini files. Run phpinfo() and see which php.ini file is being used in each case. Probably one of them doesn't have SMTP properly configured.
Apparently new-server-owner was smart enough to not let apache run as root. All fixed now. Thanks #EdHeal

Sendmail Wamp 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.

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

php redirect email to file

I am using php5.
Are there some settings or a simple php.ini directive that would redirect all the emails to a folder?
I want on the development machine to have all the emails generated by the system not sent to the actual receiver but put in a folder.
Thanks.
I used to have some code like this (kinda pseudocode):
define ('DEBUG', true);
function send_email($to, $subject, $body) {
if (DEBUG) {
file_put_contents('some_folder/' . $to . date('dmY-His') . '.html', $body);
}else{
// Actual code to send email
}
}
But i agree with others, it's easier/better to setup an development email account to receive those emails.
I don't think you will be able to do something like this. Mails are sent by a mail server so it must be your mail server that writes them to a file instead of sending them.
Why not simply send it to a special development email?
Sample:
define('DEBUG', true);
if(DEBUG)
{
// Override recipient
$recipient = 'development#domain.tld';
}
// Send mail...
No settings that I'm aware of in PHP itself. However, if you're using Postfix on your development server, here's a recipe I cooked up to redirect all outbound email to a single (local) address:
/etc/postfix/main.cf: (add this to the existing file, don't replace everything)
virtual_alias_maps = regexp:/etc/postfix/virtual
/etc/postfix/virtual:
/.*/ duskwuff#localhost
You can configure your mail server to accept SMTP messages as normal, but make it unable to forward them onto another mail server. If your mail server supports it, make it redirect all messages to a postmaster account, or any other address of your choice.
This means that PHP will behave as normal, everything will appear to work straight away with the message, but it just won't go to the 'intended' recipient.
It also means that you can inspect headers (pretty much as they would normally appear), to support debugging.
There are many ways to do this. Basically, you need to define the sendmail command in your php.ini to point to a program or script which will save the mail locally.
One solution is this:
Catch emails with php script
Another is this:
Mail catcher

cannot initiate mail function in joomla

I am getting this error in Joomla while sending the mail.
I am not getting this error every time. But some times its shows me "cannot initiate mail function".
Any solution for this?
That could be any number of things, but a general list of things to check would be first, your Joomla config:
Admin panel > Global Configuration > Server > Mail Settings > Mailer
Make sure that's set to use the PHP mail function. If it is, try making a script called test.php and putting it in the root of your site (where the index.php file is for Joomla). Make that file something like this:
<?php
$to = "you#youremailaddress.com";
if( mail( $to , 'This is a test message.' , 'Is this working?' ) ) {
echo 'Email sent.';
} else {
echo 'Email failed to send.';
}
?>
Make sure you change the $to = line to your email address.
Now go to that script: http://www.yourjoomlasite.com/test.php
You should see the text 'Email sent.' in your browser and then receive an email to that address you entered. If not, then you should contact your hosting provider and ask them to upgrade to the latest PHP version and/or resolve the mail() function issue for you. That is the most raw implementation of sending mail via PHP and if that fails to work then it's got to be an issue with your host.
If you are working in the local server, the mail will not initiate. So host your website in server and try it.
If you have any questions, let me know
If you are using WAMP or similar on your own machine and are getting this message then you need to install a mail server. This is the best solution on Windows.
http://www.toolheap.com/test-mail-server-tool/

Categories