Php – how to connect to postfix using php pear mail smtp class

pearPHPpostfixsmtp

I have the following script:

<?php
include('Mail.php');
include('Mail/mime.php');

$recip = "me <me@yahoo.com>";
$strSubject = "test subject";
$strMessage = "test message";
$crlf = "\n";
$headers = array('From'          => $recip,
        'Return-Path'   => $recip,
        'Subject'       => $strSubject);

$mime = new Mail_mime($crlf);
$mime->setTXTBody($strMessage);
$body = $mime->get();
$headers = $mime->headers($headers);
$smtp_params["host"] = "localhost";
$smtp_params["port"] = "25";

$mail =& Mail::factory("smtp", $smtp_params);
//$mail =& Mail::factory('mail');
$confirmation = $mail->send($recip, $headers, $body);
if ($confirmation) echo "accepted";
else echo "not accepted";
?>

I have postfix running on the server. The script gives me no php errors and postfix shows nothing in log when I execute. when I swich the factory lines (switch the commenting) the script sends email and postfix logs the connection. I put default master.cf and main.cf files for postfix, reloaded and restarted.

I am not very well versed with the email side of servers. Any info would be great. Might there be any error messages stored somewhere concerning the failure to connect? I've tried various $smtp_params options but I'm just shooting in the dark. Any ideas would be greatly appreciated.

Best Answer

On most machines with postfix installed, there's a local sendmail equivalent file, and unless you configure postfix differently, it will act as a local receiver for mail, meaning you shouldn't need to specifically configure postfix to accept mail in that manner as long as you send well formatted email with the necessary headers.

Basically, if it's local, there's no need to configure pear as though the mail server is on another machine.

Nick

Related Topic