Monday, May 27, 2013

Email via PHP for YAHOO SMALL BUSINESS PAGES

The normal PHP function for sending email:
mail($email,$subject,$msg);
may be used to send email from a PHP script on Yahoo! WebHosting web sites.You need to enable this by usinghttp://help.yahoo.com/help/us/webhosting/php/php-17.html. You can see an example of sending mail via a PHP script by clicking in the "Feedback" link at the bottom of the page. [NOTE: if you copy that code, please change the value of the $to variable.]

Restrictions

Yahoo! places 2 restictions on the ability to send mail:
  1. A limited number of recipients may be sent mail each day
  2. You must specify a return address that is in your own domain
They do this so we can't SPAM the world (at least not on the same day) and all the mail we send is traceable back to us. They don't count mail sent to addresses in our own domain so you can send copies to yourself without reducing the number of people to whom you can send mail each day.

Error Reporting

So, you may ask, how do we know if the mail went through?
If the return address is valid then "bounced" mail will be sent back to that mail account.
You can tell if the mail got past their checks for return address and recipient count by looking at the "/tmp/mailError.log" file. You can use code like this to automate the check:
$eLog="/tmp/mailError.log";
//Get the size of the error log
//ensure it exists, create it if it doesn't
$fh= fopen($eLog, "a+");
fclose($fh);
$originalsize = filesize($eLog);

mail($email,$subject,$msg);

/*
* NOTE: PHP caches file status so we need to clear
* that cache so we can get the current file size
*/
clearstatcache();
$finalsize = filesize($eLog);

//Check if the error log was just updated
if ($originalsize != $finalsize) {
print "Problem sending mail. (size was $originalsize, now $finalsize) See $eLog
";
} else {
print "Mail sent to $email";
}

No comments:

Post a Comment