why is php mail script not sending mail - php

<?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";

Related

Mail Function not working in 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....

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() function not returning true or false - script just times out

The php mail function has stopped working on a Centos 5.7 server. The scripts containing the function call were working on this server until the last couple of days but there have not been any configuration changes..
Whenever I call the mail() function the PHP script just stalls/freezes on that line until it reaches the script timeout limit.
$msgheader = 'MIME-Version: 1.0' . "\r\n";
$msgheader .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$msgheader .= "From: Test Name <no-reply#servername.com>\r\n";
echo "About to send mail ->";
mail ("test#servername.com", "Test Subject", "Test Body", $msg_header);
echo "Script never reaches this line!";
I have modified the email addresses for this question, but I know they are not the issue as the script executed correctly previously.
I have tried changing the email address to various personal accounts (e.g. #yahoo.com) and it still doesn't work, so I don't think this is due to spam filtering at the organization where my users reside.
What could be causing the mail function to get stuck until the script timeout rather than just immediately return false if it can't send the email? What settings can I look at?
Thanks!
EDIT:
There are no errors in the Apache error logs
php.ini has:
SMTP = localhost;
smtp_port = 25;
sendmail_path = /usr/sbin/sendmail -t -i
This issue was related to a problem with the DNS settings of the server.
After attempting:
yum update
it became clear the server was having an issue connecting to the internet. This explains the long timeouts attempting to make the outbound connection to send the email.
I had to add
search localdomain
to my /etc/resolv.conf file in CentOS to establish the outbound connection. This question was better posted on ServerFault now that I know that issue.

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.

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