bradgrafelman;10958376 wrote:What you posted isn't an "SMTP authentication script" - it's a PHP script that uses the PEAR::Mail package to send e-mails.
The internal mail() function doesn't support SMTP authentication, so you'll have to switch to using PEAR::Mail (or another 3rd-party e-mail class) if this is a feature you require (which it sounds like you do).
Hello thank you for reply. I'm a newbie to PHP and I need help from experts like you, after your explanation I understood that above code is related to "PEAR::Mail" what I try to do here is something like this :
include ("Mail.php");
function send_mail ($email_id,$to, $from, $info)
{
global $settings;
$q = '' . 'select * from hl_emails where id = \'' . $email_id . '\'';
$sth = mysql_query ($q);
$row = mysql_fetch_array ($sth);
if (!$row)
{
return null;
}
$text = $row['text'];
$subject = $row['subject'];
reset ($info);
foreach ($info as $k => $v)
{
if (is_array ($v))
{
continue;
}
$v = preg_replace ('' . '/(\\$)/', '\\\\$', $v);
$text = preg_replace ('' . '/#' . $k . '#/', '' . $v, $text);
$subject = preg_replace ('' . '/#' . $k . '#/', '' . $v, $subject);
}
$text = preg_replace ('/#site_name#/', $settings['site_name'], $text);
$subject = preg_replace ('/#site_name#/', $settings['site_name'], $subject);
$text = preg_replace ('/#site_url#/', $settings['site_url'], $text);
$subject = preg_replace ('/#site_url#/', $settings['site_url'], $subject);
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$host = "mail.domain.com"; // this will be ur smtp server like mail.domain.com
$username = "admin+domain.com"; // above message from must have to be same as here too.. mean sender of email shall have smtp ac on ur domain its must and u use the same email id its too must to be more better for mails
$password = "password"; // this is email id password becz it will use email id smtp online in php itself to generate email so here u need actual email id password.
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $subject, $headers, $text, '' . 'From: ' . $from . ' Reply-To: ' . $from);
}
for $host = "mail.domain.com", $username = "admin+domain.com" ,$password = "password"; I used my server configuration, but this code didn't work. What I try to do here is combine both scripts under the "function send_mail" and sent out a email from the server. Can you please tell me what's wrong with the above code and how to make it work.