How to configure email from a php server using exim4?

Posted on 2007-10-11
Medium Priority
Last Modified: 2013-12-18
I currently have a web server running apache/php.  We want to be able to send e-mail through the php command mail().  I was told that you need to install either exim4 or a program similar to that.  I am running Ubuntu so I want to the Synaptic packet manager and I downloaded and installed exim4.  What I have found out so far is that you need to update the php.ini file in order to be able to do this.  I have edited two parts of the php.ini file.
sendmail_path = /usr/sbin/sendmail -t
sendmail_from = me@myserver.com
I am not sure if that is right, if anyone knows please tell me?
Next I need to be able to configure Exim4 since I have not done that yet.  Can anyone tell me how to configure exim4 so that it will work?
I think once I get the php.ini file configured properly and then I get the exim4 stuff set up right it should work.  If that is not the case please let me know.  
Question by:sevenpeaks
  • 5
  • 4

Expert Comment

ID: 20063822
LVL 17

Accepted Solution

nplib earned 1500 total points
ID: 20065488
I would use PHPMailer


it was much easier to use.

We are using Apache2, PHP on Ubuntu. And Mail was a pain in the neck to get working. PHPmailer, the installer does a lot for the config, and then it just worked.

Try that out, they have a very good tutorial on how to use it as well.

Author Comment

ID: 20065689
Ok, I  am trying to use the phpmailer program.  I have downloaded it and have placed the class.phpmailer.php into the web directory.  I have edited the php.ini file so that the only line that i have changed is sendmail_path = class.phpmailer.php.  So when I do a test I am getting errors, so I guess that I have not configured it correctly.  Any ideas of what  I am doing wrong?
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

LVL 17

Assisted Solution

nplib earned 1500 total points
ID: 20066159
comment out the sendmail_path


You put the class.phpmailer.php in your web dir.
in your php file
require("class.phpmailer.php"); //make sure it's the relative path to the phpmailer file

$mail = new PHPMailer();

$mail->Host = "ipaddress of smtp server";
$mail->SMTPAuth = false; //or True if your smtp server requires authentication.
///comment out the following two lines if your smtp server requires authentication.
//$mail->Username = "username";
//$mail->Password = "password";
//end of authentication
$mail->WordWrap = 50; //or how many characters you want it to be before it wraps. If you do not //provide a value it will go on for a long time.
$mail->IsHTML(true); //false if you want plain text, but HTML is always better.
$mail->From = "from@emailaddress.com";
$mail->FromName = "You Name";
$mail->AddAddress("to@emailaddress.com", "");
$mail->AddReplyTo("reply@emailaddress.com", ""); //this can be the same has from
$mail->Subject = "subject";

$mail->Body = "The body of your email, if html is true then you can place html tags here.";
if (!$mail->Send())
   echo "Message was not sent <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;

Author Comment

ID: 20067959
Yeah once I added the class.phpmailer.php file and the smtp.phpmailer.php file to the web directory then it worked great.  You don't even have to edit the php.ini file at all.   Thanks for your help. This was a lot easier then exim.
LVL 17

Expert Comment

ID: 20067976
Thats why I recommend phpmailer all the way.
I like simple.
Why did I become a programmer?
LVL 17

Expert Comment

ID: 20067983
Why "B"?

did it not solve the problem?

Author Comment

ID: 20068095
I guess I gave you a B becuase you didn't say anything about the class.smtp.php file that needed to be included.
Also, I didn't have an installer when I downloaded it.  I had to figure out that it didn't need to be installed, that it was just two files that need to be added to the web directory.  
LVL 17

Expert Comment

ID: 20068122
the class.smtp.php file is not to be touched.

just by using $mail->IsSMTP();
it uses that file. Go through line by line of the class.phpmailer.php if you don't believe me.

Author Comment

ID: 20068138
I know it doesn't have to be touched, but I didn't even know that I had to move it to the directory.

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

The main intent of this article is to make you aware of ‘Exchange fail to mount’ error, its effects, causes, and solution.
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

850 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