A few days ago, i can send email via mail() function on my server. But now, mails doens't sending . There isn't anything at error log. I don't get any error. I don't know, why emails not sending.
What can i do? How can i solve this?
EDIT
Now i get all emails (about 18 mails :) ) . Why mails delayed?
PHP's mailer function does not actually deliver the mail. It simply hands it off to an SMTP server for that. Whether or not it actually gets delivered is not considered by mail(), it's just concerned with the hand-off.
If the SMTP server accepts it, then mail() will return true and pretend everything worked fine. The SMTP server may delete the mail, send it to the wrong place, route it through a tangle of other SMTP servers causing the mail to be delayed by a year, etc..., but mail() will still have said everything's fine.
The place to look for the cause of this is your mail server's own log. If there was a delivery problem, there'd be a list of each delivery attempt in there somewhere.
Have you tried doing this?
The problem seems to be that PHP use
the ini directive sendmail_from to set
the from email address in the SMTP
protocol. If this is not correctly
set, or if it does not match the from
header in the email headers, the email
is caught by spam protection software.
The simplest solution is to set the
directive during execution:
ini_set("sendmail_from", $email_from);
$headers = "From: $email_from";
mail($to, $subject, $message,
$headers);
Ok, now i have got 18 mails together. I don't know, why mails are delaying.
Maybe your receiving mailserver implemented greylisting (http://en.wikipedia.org/wiki/Greylisting) ...
Do you have access to the mailqueue or maillog of your webserver? In that case you can search for delayed or bounced messages there.
Related
I stumbled on the following script today for sending an e-mail using PHPMail.
<?php
$to = "some_address#domain.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "my_address#domain.com";
$headers = "From:" . $from;
mail($to, $subject, $message, $headers);
echo "Mail Sent.";
?>
Above can be runnable through php mail.php and instantly you'll get an e-mail sent to $to from $from despite not needing to set outgoing/ingoing servers out.
It really intrigued me, since my CMS uses an SMTP outgoing server (well, same way Mail PHP does), which I need to set up with my Outlook SMTP username and password - some sort of verification.
However, about Mail PHP just.. sends an e-mail. To the address you set it as. From the address you set it as.
Looking at PHP docs it does not really reveal how it works. Does Mail PHP not have any issues with spamming since anyone can send anyone anything anytime programmatically without verification of the from identity?
EDIT:
It's rather funny the people in the comments were talking about the POTUS, since I had the exact thing in mind:
It did land in my junk folder, but I'm sure it isn't hard to make this look convincing enough and still be considered "oh damn spam filter lost my e-mail!"
The mail function uses the settings from php.ini. The details of this configuration can be found in Mail Runtime Configuration.
The defaults can be set in php.ini, although you can override them using ini_set.
I bet you sent the mail from a PHP script on a hosted server. That server probably has SMTP settings configured beforehand. If you would try this locally on a WAMP/LAMP server, you would have to do this configuration yourself, since PHP cannot read your Outlook/WhateverMailclient settings.
As stated in the comments, you can specify the sender/from address yourself. SMTP doesn't require this to be the actual sender domain, so that's why this works. The missing link is the pre-configured SMTP server of your host.
Some relay servers do check for this, and your mail might be blocked or sent to a junk mail folder. You can however configure this in your DNS to indicate that <Your server's IP> is indeed allowed to send email for <yourdomain>. For more information about that subject, you might want to read this question on ServerFault.
It uses the smtp protocol or send_mail, you can even configure what php should use to send mails in php.ini. It can send e-mail but the e-mail will end-up in your spam filter take a look to DKIM and SPF records for more information
I am running into a problem with zend mail sending functionality.
I have a functionality where we have set up some cron jobs and those cron jobs processes some php script and then sends a mail. Actually mails are going fine, but sometimes it is getting dropped into spam directory. After some research I have found that the return-path of mail body is causing problem. Since the mail sending script us as a root, so the return-path is root#domain.com and I want change it to support#domain.com
Is there any way I can achieve that.
Note: I did try to add that in headers, but it is not working.
It's return-path not reply-to... There's no such thing as reply-path :)
There are lots of parameters for being marked as spam and I'm not sure it's because of return-path only. You have to fix it though and you can try by altering the headers while sending:
$mail = new Zend_Mail();
$mail->addTo($this->email, $this->name)
->setFrom($message->from_email, $message->from_name)
->setSubject($message->subject)
->setBodyHtml($message->getHtmlEmailContent($subscriber))
->setBodyText($message->getTextEmailContent($subscriber))
->setReturnPath($settings->get('return_path'))
However SMTP servers might override this (gmail definitely does). Just open the email in raw and see if your header is there and if it's overriden or not.
If mails are marked as spam in your test account randomly you might want to check the contents and subject of your email. SPF records for your SMTP domain is important too.
See https://www.campaignmonitor.com/blog/post/1971/what-are-some-good-methods-for
and http://mailchimp.com/resources/guides/how-to-avoid-spam-filters/ for some details.
See this answer for the explanation of reply-to and return-path.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I want to script a simple registration form with activation mail and so on. But for some reason mail() doesn't send the emails, or my 3 different email accounts (hotmail,gmail,yahoo) don't receive them and therefore don't even put them in the spam folder.
Code:
<?php
$mailto = 'xxx#example.com';
$subject = 'the subject';
$message = 'the message';
$from = 'system#example.net';
$header = 'From:'.$from;
if(mail($mailto,$subject,$message,$header)) {
echo 'Email on the way';
}
?>
Everytime it outputs 'Email on the way' so mail() returns true, right? I really don't get it, I've even tried to turn off my little snitch (although I didn't block SMTP).
See this article by Jeff Atwood.
In short: Just because your code has handed the e-mail to a Mail Transfer Agent, it doesn't mean it will be delivered. Yes, mail() returning true means "accepted for delivery" - which means "Looks like an e-mail, I'll try to deliver this", not "It is delivered". Even the manual for mail() says:
It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.
Soooo: check your MTA (is the e-mail sent from your local computer?), try to send to a local address (if the address is local, does it get delivered?), try to send an e-mail from your mail client, using the same settings as your PHP script, try to send to a smaller mail-hoster which allows you tu switch off antispam (is it delivered outside your network?). Also, read that article, and check the points mentioned there.
Maybe your server is not configured to handle mail().
<?php
print phpinfo();
?>
and look at sendmail_path
You may need to add correct end of line characters to the Headers. It may be \n or \r\n
Check your phpinfo and/or php.ini for your mail settings and make sure you can send mail with whatever program php is trying to use. The function will succeed if the command executes but doesn't know if the mail actually went out.
Check your mail server's mail log. On Unix-ish systems, it's generally /var/log/maillog. On Windows, who knows, but there should be a log somewhere. If mail is returning TRUE, then whatever mail server it's connecting to has accepted the mail for eventual delivery. After that, mail() is no longer involved in any way and it's up to the SMTP servers to do the actual delivery.
In real world terms, mail() is you walking a letter down the block and dropping it into a mail box. Everything after that is utterly outside of PHP's scope and control.
If this is a linux server it's probably set up to send to the local mail queue. When I had this problem I got it working by adding an MX entry on the DNS server used by the linux servers which pointed to our ISP's mail server.
I had the same problem on Ubuntu and I resolved it following the next tutorial:
http://www.nixtutor.com/linux/send-mail-with-gmail-and-ssmtp/
I hope it works for you also.
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.
I have currently the following and it's not working. (normally I have a body text and header information, but nothing works)
mail("idealvisions#live.com","Nieuw offerte aanvraag","test");
We'll on my server it did because I'm running php 5 or higher, no problem there. But the contact page is from a client which runs php 4.4 I believe. Now the client is really pushing me to get this fixed but it won't seem to fix. I've tried everything
What's the problem here? is it the php version?
I checked also with phpinfo and have this
sendmail_from no value no value
sendmail_path /usr/local/bin/bgc_webhosting_mailer.sh /usr/local/bin/bgc_webhosting_mailer.sh
This sounds like the Client's server is not set up properly with a mail-sending handler
some ISP's that provide hosting and some free hosting platforms disable the mail function, can you try something like this:
error_reporting(E_ALL);
if (mail ('you#yourdomain.com', 'Test subject', 'Test Body')){
echo 'Mail sent';
}else{
echo 'Mail not sent';
}
if there is an issue with mail() on their server you could consider posting to a mail form on one of your servers and then bouncing them back to a thankyou page on the client's server after.
From the sendmail path, your host uses a custom sendmail program/shell script.
Since the sendmail from isn't set, you have to set it within the mail() function, unless it is hardcoded into /usr/local/bin/bgc_webhosting_mailer.sh in which case you should ask the hosting.
Example setting sender:
mail('recepient#example.com', 'Test subject', 'Test Body', "from:sender#example.com\n");
If the mail() function really is NOT available, then ask your hosting about an alternative, such as their local SMTP server.
You can then use the local SMTP server to send email. Probably the easiest way to do this is donwload an email library that supports sending via SMTP such as PEAR Mail or SwiftMailer for example.
Pear: http://pear.php.net/package/Mail
Swift: http://swiftmailer.org/
If your host does not provide an SMTP server, you should probably look for a different host. However, you can always use a free email service such as Gmail, or Yahoo and send mail through their SMTP.
Also check SeLinux, it can prevent any thread spawned by Apache to send mail. In that case you get no error and no mail.