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/
Related
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
I have an issue regarding debian server. The same code I uploaded on cloud server and the contact form (with php) is working properly and is sending email.
I tested exactly the same code in our server in the office with Debian and it does not shows any error but we could not accept emails from contact form.
Thank you in advance
You can't send emails from local server directly
You can take a look at this question
Send email from localhost
localhost term means it's not equipped with mail capability
even though you can try this code to know if it has built in mail server or not
if (mail('email address','subject','message') === true){
echo 'SENT';
}else{
echo 'NOT SENT';
}
Here is the code I have in contact.php:
<?php
mail('philovesdogs#gmail.com','sdf','sadfsad');
echo 'Ok';
?>
I put the echo in just to make sure that PHP was working on the page. I uploaded the page to my LAMP server and opened the page. I saw ok. I checked my email however (and my Spam folder) and no email was sent.
You need to configure and keep running SMTP server. Review questions like this: Configuring LAMP to Send Mails
I'm working on a php project where all emails are sent via the mail() function.
That's quite a problem to prepare and test those emails because mail() function fails on the localhost and I should constantly rewrite my code to print out the email before sending, check it and asume that on server it would be sent ok.
Is there a way to somehow manage such situations?
I will be very happy if there is a way to save the messages on hard disk or send them only to the one specific email address, not to the real recipients, without or with slight modification of the code. Some useful software or advices are so appreciated.
Thanks!
P.S. On the localhost I'm using WAMP package as a webserver.
http://www.toolheap.com/test-mail-server-tool/
Test mail server tool for Windows is awesome! Every time you send an email on local host, it just pops that email up in your favorite email reader (I.e. outlook, postbox etc)
I use it exclusively to test all my web apps on WAMP!
No server changes needed - just download and install - then send an email and see it in action.
Oh - and it's free!
Here is the solution I found to get around this problem.
1. Create the sendmail.php file somewhere in the wamp dir, e.g. d:\wamp\apps\sendmail.php. Here is it's source:
/* Path where emails will be stored */
define('DST', 'd:/wamp/tmp/sendmail/');
/* Extract the message from the stdin */
$message = '';
while(($line = fgets(STDIN)) !== false) {
$message .= $line;
}
/* Save message to file */
file_put_contents(DST.date('Y-m-d_H-i-s_').md5($message).'.eml', $message);
2. Uncomment and edit the sendmail_path parameter in the php.ini to this:
sendmail_path = "D:\wamp\bin\php\php5.3.5\php.exe D:\wamp\apps\sendmail.php"
All messages that are sent via the mail() function will be captured and stored in the specified directory.
Install fakemail. It acts as a local SMTP server and saves all mails in a folder.
You could wrap the mail() function, like:
function my_send_mail(/*...*/) {
if (is_localhost()) {
// just save the mail to text.
} else {
// call mail() and send mail
}
}
And use this function instead of use mail() directly.
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