SMTP Authentication for an OLD PHP script

Well this is my first post here, Im fairly new at PHP mostly I have thinkered with HTML

I have been using a fairly old PHP script for a classifieds website for a Military base I used to live at a few years back. IT used to work fine using the sendmail option, but because of the updates to PHP it doesn’t work as well as it did
The server is a Linux with PHP Version 5.3.21
So the sendmail function uses the EXIM and so this is causing emails to be returned or not accepted by various domains, because they are not authenticated.

I desperatly need help converting the code within the script, to be able to send email via SMTP.

I have locate the code to send out the emails (at least I think I did) and have tried to use some tutorials out there to convert it, but have not had much luck with it

Bascially the code is included in the FUNTIONS.PHP page
Here is the code
[php]function sendEmail($aTo, $aFrom, $aSubject, $aBody)
{
global $set_ini_smtp, $quiet,$from_address_mail;

if (!$aFrom) 	{ 	die(failMsg("No sender (Code #100)","No sender is specified."));			}
if (!$aTo) 		{ 	die(failMsg("No reciept (Code #101)","No recipient is specified."));	}
if (!$aSubject) { die(failMsg("No subject (Code #102)","No subject is specified."));		}
if (!$aBody) 	{ 	die(failMsg("No body (Code #103)","Nobody is specified."));				}

if ($set_ini_smtp)
	ini_set("SMTP",$set_ini_smtp);

$aBody = ereg_replace("<br>","\n",$aBody);
$headers = "From: $aFrom\r\n";
if (!$quiet)
{
	if (!validateEmail("$aTo"))
		die(failMsg("Problem sending mail","Email address TO: '$aTo' does not appear to be a valid email address."));		
	if (!validateEmail("$aFrom")) 
		die(failMsg("Problem sending mail","Email address FROM: '$aFrom' does not appear to be a valid email address."));		
	if (!mail("$aTo", "$aSubject","$aBody","From: $aFrom\r\n")) 
		die(failMsg("Problem sending mail","For some reason, one or more emails were not sent. To: $aTo, From: $aFrom, Subject: $aSubject"));		
}
else
{
	mail("$aTo", "$aSubject","$aBody","From: $aFrom\r\n"); 
	//mail("$aTo", "$aSubject","$aBody","From: $aFrom<$aFrom>\nX-Mailer: PHP 4.x\r\n\r\n"); 
		
}
	
return true;	

}
[/php]

Because of this script being a classifieds site, it sends out all kinds of emails…registration, confirmation of accounts, when new ads are posted, or when someone contacts a seller.

I’m willing to give it a few more runs to see if it will work is anyone here is willing to help me out.

Thank you in advance for any assistance

First I would recommend wrapping the code in a try catch statement, this will tell you if there are any errors. Second, you could look into using a library such as PHPMailer, it can be configured with several different sending types and enables you to send more complex newsletters.

Here is a article on the difficulties you face with sending emails. http://amecms.com/article/Sending-email-in-PHP-and-reaching-the-inbox

Any suggestions for anyone that could help me change my OLD code to a new code that will use SMTP Authentication - I’m willing to pay $$$ to get the file changed so that the entire script can then use the SMTP Authentication.

Thank you

Sponsor our Newsletter | Privacy Policy | Terms of Service