[BlueOnyx:07835] Re: php mail function issue

Michael Stauber mstauber at blueonyx.it
Mon Jul 25 07:14:45 -05 2011


Hi Charles,

> Are you sure this is PHP's mail function and not PEARs mail function?

That is a good point. I've always found PHP's mail() function lacking and 
usually either used one of the available PEAR functions instead, or more 
recently switched to an external class that handles sending mails in a much 
better fashion.

Here are some good examples:

http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm

A very good PHP class for sending emails is this one (which is what I'm 
using):

http://sourceforge.net/projects/phpmailer/

It can send emails using SMTP-Auth using SSL for the transmission, adds proper 
headers (even custom ones) and allows you to easily send multipart messages 
that consist of an HTML part and a text part. You can even let it use multiple 
relay servers for sending mails. So if one relay is down, it'll use the other 
specified one.

A small usage example would be this:

  // send email

    $mail->PluginDir = "/path/to/external-library";
    require("/path/to/external-library/class.phpmailer.php");

    $mail = new PHPMailer();

    $mail->IsSMTP();                                   		// send via SMTP
    $mail->Host     = "mail.relay1.com;mail.relay2.com"; // SMTP servers
    $mail->SMTPAuth = true;     // turn on SMTP authentication
    $mail->Username = "username";  // SMTP username
    $mail->Password = "password"; // SMTP password

    $mail->From     = $emailField;
    $mail->FromName = $fullNameField;
    $mail->AddAddress("username at domain.com");
    $mail->AddAddress($emailField,$fullNameField);
    $mail->AddReplyTo($emailField,$fullNameField);

    $mail->WordWrap = 50;                              // set word wrap
    $mail->IsHTML(true);                              // send as HTML

    $mail->Subject  =  $subject;
    $mail->Body     =  "$message<br><br>";
    $mail->AltBody  =  "$message \n\n";
    $mail->WordWrap = 50;

    $mail_status = $mail->ErrorInfo;

    if(!$mail->Send()) {
        $mail_status = "ERROR: Email could not be delivered! Please make sure 
that your server can make outgoing SMTP connections and that it can resolve 
DNS propperly!";
    }
    else {
        $mail_status = "Email was sent!";
    }


-- 
With best regards

Michael Stauber



More information about the Blueonyx mailing list