Question

My mail function is not working. My mail function is as follows:

function sendmail($from,$to,$sub,$msg)
{

   $subject=$sub;
   $message=$msg;
   $headers = "MIME-Version: 1.0" . "\r\n";
   $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
   $headers .= "From: <'.$from.'>" . "\r\n"; 
   mail($to,$subject,$message,$headers);
}

This works fine in some of my other project but not working in a new project of mine.

Was it helpful?

Solution 3

 I finally solved the issue. The problem was I had given my gmail id as admin id  ( i.e, from address) now i changed it to a mail id from the domain name(say, if the domain name is www.abc.com I gave id as noreply@abc.com) and it works.

And now i came to know that giving gmail or other mail ids will work in some cases in some servers but it wont work on all servers. So using mail id in domain name (noreply@abc.com) will solve this issue. Even though gmail ids works in some servers still it will give a error message in the body of mail or it will be a spam mail so it is better to use mail id derived from domain name like noreply@abc.com.

Thank You....

OTHER TIPS

It may be mail not working in your server. Check with a basic mail function and upload it in your root to test mail.

testmail.php

<?php
$msg = "This is test mail";
mail("tester@email.com","My subject",$msg);
?>

If mail not working then try with authenticated mail like phpmailer, sendmail.

PHP inbuilt mail() function wont work in ur localhost or the server WHICH DOES NOT support smtp server. If you are running this project in ur pc locally then this mail function wont work. you need to upload it in server and then try, it will work!

If you are running this project in server and your mail doesn't fire then possibilities are :

1) You are hosted it in Windows server which supports PHP but not smtp.

2) If server is Linux, then server might have disabled outgoing mail. pls contact your server

I suggest you to use PHPMailer [https://github.com/Synchro/PHPMailer] which sends mail through external SMTP server like GMail,Hotmail etc.. give it a try..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top