Jump to content

Can't send email using PEAR Mail. Works on one server, but not another.


Recommended Posts

I've been through quite a bit of research, trial, and error, but I know almost nothing about Linux, server-side programming, email, or PHP's PEAR library -- all of which, i'm using :P

 

I've got a PEAR Mail 'send' WORKING JUST FINE FROM MY OWN PERSONAL SERVER on a PHP page. On a client's server, I've got linux w/ PHP and PEAR installed okay. But, sending mail from PHP or linux's "sendmail" function from their server is not working. (I'm not sure I'm using 'sendmail' correctly) BUT, I used linux's "Netcat" utility on that server to send mail just fine.

 

My friend suggested I try changing the "sendmail_path" parameter in my "Mail::factory" call. I think this is a great idea. I've tried changing it once and I'm trying more paths now, but I can't think of all the paths that might lead to the email script my server is using. Default is "/usr/sbin/sendmail" and I've tried "/etc/mail/sendmail", also.

 

So, I'd like to know:

- possible sendmail script paths on linux

- possible ways to test whether email is working on linux

 

Here's my PHP code:

$from = "[email protected]";
$to = "[email protected]";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$auth = false;
$debug = true;
$host = "fake.fake.fake.com";
$port = 25;
$username = "[email protected]";
$password = "fakefakefake";
$sendmail_path = "/usr/sbin/sendmail";
$headers = array (
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp',
array (
	'host' => $host,
	'port' => $port,
	'auth' => $auth,
	'username' => $username,
	'password' => $password,
	'sendmail_path' => $sendmail_path
)
);
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}

My solution:

 

 

$email = <<< EOF
HELO smtp.server.com
MAIL FROM: [email protected]
RCPT TO: [email protected]
DATA
Body of email
.
QUIT
EOF;

$emailFile = fopen ('/tempEmailFileForSending.txt', 'w+');
fwrite ($emailFile, $email);
shell_exec('nc -v smtp.server.com 25 < /tempEmailFileForSending.txt');

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.