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 = "fake@fake.com";
$to = "fake@fake.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$auth = false;
$debug = true;
$host = "fake.fake.fake.com";
$port = 25;
$username = "fake@fake.com";
$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>");
}

Link to comment
Share on other sites

My solution:

 

 

$email = <<< EOF
HELO smtp.server.com
MAIL FROM: noreply@server.com
RCPT TO: recipient@domain.net
DATA
Body of email
.
QUIT
EOF;

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.