Xenland
Xenland

Reputation: 510

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

Upvotes: 1

Views: 771

Answers (5)

Mickle Foretic
Mickle Foretic

Reputation: 1409

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' => '[email protected]',
        '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('[email protected]', 'User Name');

//Send it!

try {
    $mail->send();
} catch (Exception $e){

}

Upvotes: 4

datasage
datasage

Reputation: 19563

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.

Upvotes: 0

John
John

Reputation: 10146

PHPMailer

Here are a bunch of examples on how to use php mailer

http://phpmailer.worxware.com/index.php?pg=examples

Upvotes: 0

jerjer
jerjer

Reputation: 8760

try PEAR MAIL

Upvotes: 1

Related Questions