Mail Function not working in php - php

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.

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

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

Related

send email in php using xampp server?

i want to send email using php through xampp server.here is my code
<?php
$to = 'atchibabu#solbaacken.com';
$subject = 'My Email';
$msg = "please find details";
// Make sure to escape quotes
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: My Site Name <atchibabu516#gmail.com.com>' . "\r\n";
if(mail($to, $subject, $msg, $headers))
{
echo "success";
}
else
{
echo "fail";
}
?>
when i execute i get "success" message but i didn't get any mail i am waiting still one hour
i don't know why it's happening. some suggestions send email using smtp so can any one guide how could i use the smtp.i am using mac xampp so any one guide me i could i install smtp in mac xammp.
thanks for advance.
Few things to note:
Your from has 2 .com so, probability of your message going in SPAM is almost 90%.
Check your phpinfo(); output. What does sendmail_path show? Do you have that software installed? Ideally it is /usr/sbin/sendmail -t -i and the software is sendmail in ubuntu machines.
Also, in your phpinfo(), check the SMTP port. Also there is a high possibility of getting blocked by a firewall or similar software, checked it already?
You should configure your email on localhost
here is the step by step way to configure your smtp
Open the “php.ini“. You should know where it is located because it depends upon the particular server you’re running.
Search for the attribute called “SMTP” in the php.ini file.Generally you can find the line “SMTP=localhost“. change the localhost to the smtp server name of your ISP. And, there is another attribute called “smtp_port” which should be set to 25.I’ve set the following values in my php.ini file.
SMTP = smtp.wlink.com.np
smtp_port = 25
Restart the apache server so that PHP modules and attributes will be reloaded.
Now try to send mail
Reff link is here
helpfull links
http://expertester.wordpress.com/2010/07/07/how-to-send-email-from-xampp-php/
Edit your SMTP. If you want to test it in your localhost, try installing Mozilla Thunderbird for localhost email and create new account using Mercury from Xampp.

PHP mail not working for some reason

I am new to PHP and I'm using the mail function to send emails which is not working. I get a success message, but still it does not work
same code
<?php
$email_to = "abc#abc.com";
$email_subject = "Test mail";
$email_body = "Hello! This is a simple email message.";
if(mail($email_to, $email_subject, $email_body)){
echo "The email($email_subject) was successfully sent.";
} else {
echo "The email($email_subject) was NOT sent.";
}
?>
Am I missing anything, do I need to include any files for this function.. I am from asp.net & this is the basic script which found on website.
I tried other scripts related to mail they didn't work either..
I AM RUNNING THIS SCRIPT ON THE WEBSITE NOT on the localhost
If you are using Ubuntu and it seem sendmail is not in /usr/sbin/sendmail, install sendmail using the terminal with this command:
sudo apt-get install sendmail
and then run reload the PHP page where mail() is written. Also check your spam folder.
This is probably a configuration error. If you insist on using PHP mail function, you will have to edit php.ini.
If you are looking for an easier and more versatile option (in my opinion), you should use PHPMailer.
This might be the issue of your SMTP config in your php.ini file.
Since you new to PHP, You can find php.ini file in your root directory of PHP installation folder and check for SMTP = and smtp_port= and change the value to
SMTP = your mail server e.g) mail.yourdomain.com
smtp_port = 25(check your admin for original port)
In case your server require authentication for sending mail, use PEAR mail function.
"Just because you send an email doesn't mean it will arrive."
Sending mail is Serious Business - e.g. the domain you're using as your "From:" address may be configured to reject e-mails from your webserver. For a longer overview (and some tips what to check), see http://www.codinghorror.com/blog/2010/04/so-youd-like-to-send-some-email-through-code.html
The mail function do not guarantee the actual delivery of mail. All it do is to pass the message to external program (usually sendmail). You need a properly configured SMTP server in order for this to work. Also keep in mind it does not support SMTP authentication. You may check out the PEAR::Mail library of SwiftMailer, both of them give you more options.
Check your SMTP settings in your php.ini file. Your host should have some documentation about what credentials to use. Perhaps you can check your error log file, it might have more information available.
For HostGator, you need to use the following for your headers:
$headers = 'From: user#yourdomain.com' . " " .
'Reply-To: user#yourdomain.com' . " " .
'X-Mailer: PHP/' . phpversion();
It only worked for me when the from user was host e-mail while the Reply-To can be something different e.g. From: owner#domain.com, Reply-To: info#domain.com
http://support.hostgator.com/articles/specialized-help/technical/php-email-from-header
http://support.hostgator.com/articles/specialized-help/technical/how-to-use-sendmail-with-php

Mail being sent to gmail, yahoo, but not to personal mail servers

I am facing a weird problem. When I send out mails using PHP's mail() function, the mail is being sent perfectly to gmail and yahoo(though it was marked as spam in yahoo), but the mail is not received by my company's email address.
I don't have direct access to the server, only ftp to the public_html folder, hence I can't check the logs.....
Any ideas or suggestions?
EDIT:
$mailfrom="website#mysite.com";
$mailto=$buyerrow['email'];
$subject="Test Details";
$body='Hi '.$buyerrow['name'].'!<br>Test Details below:<br><br><br><br><br>Thanks<br>Web Team';
$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; carset=iso-8859-1;\r\n";
$headers.= "From: ADMIN <".$mailfrom.">\r\n";
#mail($mailto,$subject,$body,$headers,"-f website#mysite.com");
As for the spam folders at my company's server, I am quite sure it didn't end up there either....
Is it possible that there is some server setting which allows php to send mail to only particular server?
Many company mailservers are set up to outright reject some types of spam immediately during the SMTP session. If that happens, it will never make it to your companies spam folder. You should check with your company system administrator.
If you're in doubt, you can always use an application like Wireshark to capture and analyse the actual SMTP traffic.
Have you checked on the Spam folder ? also check whether you have set HEADERS properly with from name etc.,
The problem seems to be with your company's server mail server.
Make sure to test it [send email from yahoo to your company email address] and double check the mx records.

why is php mail script not sending mail

<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail("example#gmail.com", "hello", "nothing",$headers);
echo "mail sent";
?>
but it does not actually send the mail please help me out with this
The mail function is just an interface to the local mail server. The mail functionality in PHP relies on the machine PHP is running on to be correctly configured and able to dispatch e-mail. Check the mail system configuration on the machine.
check the following -
check if your smtp server is running (you could either check through command line tools or try ftp'ing to port 25).
If your smtp server is running. Then try to send a mail manually (without script). Use the command-line mail command (I am assuming you have unix here).
Also, when you run your script, what happens? It could be possible that your mail is in a Queue. From your terminal type 'mailq'. This shows the current emails in Queue & why they are there. Also there is a corresponding log to this. You could also check that out for info.
My guess is if all the above are running, you are good to go.
please check following ** Please verify your servers sender domain policy**
Emails sent through your servers (mail servers and shared web servers) should use a from address that is hosted here at your server. Emails that are sent with a from address hosted somewhere else (like Hotmail or Google) may be blocked.
ie use
$header = "From:example#/*yourhostname.domain name*/ \r\n";

Problem with Free SMTP Server in php code

I wrote php code for use to contact us form
but I can not find free SMTP server to use it.
I Try to use SMTP Server For Gmail but I found this error.
Warning: mail() [function.mail]:
"sendmail_from" not set in php.ini or
custom "From:" header missing in
C:\www\htdocs\contactUs.php on line
25"
line 25 is :
mail ($to,$subject,$body,$headers);
statement that indicate using Gmail SMTP Server is :
ini_set("SMTP","smtp.gmail.com");
SO,can U help me ?:(
You need a From: [VALID EMAIL] header of the message when you send the message. Try doing something like this:
$headers = array(
'From: me#example.com',
'Mime-Type: text/plain; charset=utf-8',
);
$dest = 'some_user#example.com';
$subj = 'test';
$message = 'hello world';
mail($dest, $subj, $message, implode("\r\n", $headers));
Also, the mail function is meant to be used as a frontend to the mail daemon that's running on the same server the web server is running on. Since most *NIX boxes have both, it usually works.
What I would not recommend, however, is using some remote server to send your mail. It's much more efficient and reliable (not to mention looking more professional) to just have the same server send the message as the one that generated the message.
Setting up your own SMTP server is easy and free and more flexible than Gmail. Gmail WILL NOT send messages whose From: header does not match either the main account address or a connected address.

Categories