Best way to manage php email sending
I've programmed and devleoped a CMS package custom made from scratch(Apache2+PHP+Mysql+Puspoold+Bitcoin) for bitcoin mining. I have a lot of different distributions that my users use along with the choice of many emailing programs(sendmail/postfix). My application works fine on my local computer with sendmail however it seems to not work on commercial type 开发者_如何学CVPS systems including my own that is sperate from my local computer(just to make that clear).
Anyways what is the best way to go about using the mail() function in PHP? Is there a better way to get the actuall error being outputed from mail then just false? Also follow up question, sometimes the mail() reports true and it never sends. I feel so lost I usually never have this much trouble with a PHP error I get them fixed eventually this one dose't seem to want to work even after reintalling sendmail packages.
Note: I have edited the php.ini file to my needs still nothing and check around for best sendmail practices for php.
I suggest you using Zend Mail instead of the native send() php function. In order to use this, you will need to copy and include the Zend Libraries (directly on your application or within the server configuration)
Here is an example:
$config = array(
'auth' => 'login',
'username' => 'username@gmail.com',
'password' => 'password',
'ssl' => 'tls',
'port' => 587
);
$mailTransport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
Zend_Mail::setDefaultTransport($mailTransport);
$mail = new Zend_Mail();
$mail->addTo($email);
$mail->setSubject($subject);
$mail->setBody($message);
$mail->setFrom('username@gmail.com', 'User Name');
//Send it!
try {
$mail->send();
} catch (Exception $e){
}
try PEAR MAIL
PHPMailer
Here are a bunch of examples on how to use php mailer
http://phpmailer.worxware.com/index.php?pg=examples
I would normally relay all mail through a 3rd party smtp server. This can be done directly in php.ini or by reconfiguring the local mail server to relay all email.
What server you use is up to you. You can try to set up your own and manage all the issues with spam blocking, etc. Or use a third party email service like SendGrid.
Try PHPMailer :
rohitashv.wordpress.com/2013/01/19/how-to-send-mail-using-php/
精彩评论