Solved

expand php mail function to include smtp authentication..

Posted on 2011-03-01
3
294 Views
Last Modified: 2012-05-11
Hi, I have a php mail function created by someone else, which works great.

I just want to add smtp authentication to this; how can I expand my function so that I could specify an smtp host, smtp authentication, an smtp username and pass?

thanks.

<?php
 
class simple_mail{
 var $to;
 var $from;  
 var $subject;
 var $body;
 var $html;
 
 function simple_mail(){  
  $this->to   = "";
  $this->from  = "";  
  $this->subject = "";
  $this->body  = "";
  $this->html  = 0;
 }
 
 function send(){
 
  if($this->html == 1)
  {
         $headers  = "MIME-Version: 1.0\r\n";
       $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
  }
 
  $headers .= "From: ".$this->from."\r\n";
 
  if(@mail($this->to, $this->subject, $this->body, $headers)!= 1)
            return false;
  else
   return true;
}
}
?>
0
Comment
Question by:eggster34
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
psimation earned 500 total points
ID: 35014372
I would suggest to rather use PHPMailer - has all of the functionality you want.

examples: phpmailer.worxware.com/
download: sourceforge.net/projects/phpmailer/
0
 

Author Comment

by:eggster34
ID: 35016810
I'm afraid I need to expand this specific function rather than using php mailer :(
0
 
LVL 17

Expert Comment

by:psimation
ID: 35017825
the basic mail() function in php does not have comprehensive options. It basically just uses the underlying mailer program configured in your php.ini file.

You can send some command line options to the underlying mailer program using mail(), but I've never seen an example of sending smtp auth info this way.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question