SMTP Mail in PHP/Linux

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kattasrinivas
Forum Newbie
Posts: 1
Joined: Mon Apr 07, 2003 7:56 am
Location: INDIA
Contact:

SMTP Mail in PHP/Linux

Post by kattasrinivas »

Dear All,
I Have an Requirement where i need to pass the mail server name dynamically for php mail, I know it is possible but don't know exactly how it works.
Iam working with php on Linux, Here is a simple Code Iam using for mail

*****************************
$to = "kattasrinivas@etisbew.com";
$subject = "Test";
$message ='Test';

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: kattasrinivas@etisbew.com\r\n";

if(mail($to, $subject, $message,$headers)) {
echo "Mail Sent";
} else {
echo "Mail Not Sent" ;
}

***************************************
In the above Program I need to pass the mail server name dynamically, By default the mail server is considered as localhost

Any help in thsi regard is highly appreciated
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

http://www.php.net/manual/en/ref.mail.php
on non-win32-systems php uses the injection part of your MTA and the configuration for that is PHP_INI_SYSTEM so your php-script cannot change it. You cannot setup the local MTA to send the mails to another server?
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Or....

Post by llimllib »

Or, a possibly more elegant solution is to use the PEAR SMTP module. While not documented on their website, it is in the process of becoming a full package. Check it out here. Sample applications are included, and the source is very well documented.
Post Reply