Solved

expand php mail function to include smtp authentication..

Posted on 2011-03-01
3
261 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now