sendmail using phpmail

Scottie Swenson swenson at heronetwork.com
Tue Dec 2 10:24:26 PST 2003


Greetings,

We host a lot of virtual domain web sites on BSD boxes that are running PHP 
forms and sending out tons of email. Sometimes PHP doesn't figure out the right 
path for the sendmail program. So your first check is to make sure PHP is using 
sendmail correctly for your particular box. The builting phpinfo() command puts 
out a nice summary of your php build including all the build options. You need 
to make sure PHP was compiled with the correct path to sendmail.

A php check web page:
----- cut here -----
<?php phpinfo(); ?>
----- cut here -----

In the CORE PHP configuration section look for the setting 'sendmail_path'. 
Ours is set to '/usr/sbin/sendmail -t -i'

You can test to see if PHP can send email using the code I included bellow. 
Given that PHP can send email phpmail should start working.

I am not sure how phpmail handles the mail but we have found email works a LOT 
better if some extra header information is included. Here is the PHP code you 
can use to check to see if PHP is able send messages from a functioning email 
form on a BSD box:

email.php:
----- cut here -----
<?php
   $_toEmailAddress = "info at somedomain.com";
   $_ccEmailAddress = "";
   //$_bccEmailAddress = "alternate at destination.com";

   $_subject = $_POST[ "subject" ];
   $_comments = $_POST[ "message" ];
   $phone = $_POST[ "phoneNumber" ];
   $name = $_POST[ "name" ];
   $_from = "\"$name\" <" . $_POST[ "email" ] . ">";
	
	if ( $_POST[ "cc_me" ] == "on" ) {
	  $_ccEmailAddress = $_from;
	}

   $message = "\n\nName: " . $name . "\n";
   $message .= "Email: " . $_from . "\n";
   $message .= "Phone Number: " . $phone . "\n";
   $message .= "\nMessage: " . $_comments . "\n\n";

   $_headers = "";
   //$_headers .= "MIME-Version: 1.0\r\n";
   //$_headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
   $_headers .= "From: $_from\r\n";
   //$_headers .= "To: ".$_toEmailAddress."\r\n";
   if (! empty($_bccEmailAddress) ) {
       $_headers .= "BCC: ".$_bccEmailAddress."\r\n";
   }
   if (! empty($_ccEmailAddress) ) {
       $_headers .= "CC: ".$_ccEmailAddress."\r\n";
   }
   $_headers .= "Reply-To: $_from\r\n";
   $_headers .= "X-Priority: 1\r\n";
   $_headers .= "X-MSMail-Priority: High\r\n";
   $_headers .= "X-Mailer: Hero Network Email System";

   $mailresponse = mail("$_toEmailAddress",
                        "$_subject",
                        "$message",
                        $_headers
                        );
?>
----- cut here -----

email_form.html
----- cut here -----
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
   <head>
     <title>
       Untitled
     </title>
   </head>
   <body>
     <form action="email.php" method="post">
       <table border="0" width="383" cellpadding="2" cellspacing="0" 
align="center">
         <tr>
           <td width="63" style="font-family: arial, san-serif; font-size: 
12px; color: #333366;" align="right">Name:</td>
           <td><input type="text" class="name_text" name="name" size="20"></td>
         </tr>
         <tr>
           <td width="63" style="font-family: arial, san-serif; font-size: 
12px; color: #333366;" align="right">Email:</td>
           <td><input type="text" class="name_text" name="email" size="20"> 
<img src="img/required.gif" alt="Required" width="9" height="8"></td>
         </tr>
         <tr>
           <td colspan="2" style="font-family: arial, san-serif; font-size: 
12px; color: #333366;">Send a copy of this message to me too: <input 
type="checkbox" name="cc_me" checked="" value="ON">
           </td>
         </tr>
         <tr>
           <td width="63" style="font-family: arial, san-serif; font-size: 
12px; color: #333366;"><p align="right" style="text-align: right">Phone:</p></td>
           <td><input type="text" class="name_text" name="phoneNumber" 
size="20"></td>
         </tr>
         <tr>
           <td colspan="2">
             <br>
             <p style="font-family: arial, san-serif; font-size: 12px; color: 
#333366;">
               To best route your email, please select the most appropriate 
category:
             </p>
             <select class="greySelect" name="subject">
               <option class="optionRed" value="Request Information" 
selected>Request information</option>
               <option class="optionRed" value="Owner Contact Request">Send 
Message Directly To Owner</option>
               <option class="optionRed" value="Requesting 
Something">Other</option>
             </select><br>
             <br>

             <p style="font-family: arial, san-serif; font-size: 12px; color: 
#333366;">Input message here.</p>
              <textarea class="input_text" rows="20" cols="50" 
style="font-family: arial, san-serif; font-size: 12px; color: navy; 
scrollbar-base-color:pink;scrollbar-arrow-color: #ee0000;" name="message" 
size="15"></textarea>
             <p align="center"><input type="submit" value=" Send Request " 
name="Submit" style="font-family: arial, helvetica, san-serif; font-size: 13px; 
color: #ffffff; background: #006633;"></p>
             <br>
             <br>
             <br>
           </td>
         </tr>
       </table>
     </form>
   </body>
</html>
----- cut here -----

Cheers,
Scottie



More information about the freebsd-isp mailing list