[FreeBSD 5.2.1] Sendmail is being a b!tch

X-Istence said:
Doesnt matter all that much. And PHP likes to send sendmail flags which qmail-injecct might not understand.
... As I found out a few minutes ago. I sent a mail yesterday using the php mailer system, but it took 6 hours to come to me. The reason why is that it was sent from anonymous@server1.thuisnet.lan, looks like qmail-inject doesn't recognise the -f<email_from> flag. Back to sendmail (the qmail wrapper version then ;)).
 
Or you need to add some proper headers to your emails, and add your own From: Glaanieboy <something@somethingelse.com> line.
 
Nah, it's fine as it is. The qmail sendmail wrapper is good enough.
 
Uhm...
Code:
    $site_title = $settings_fetch['title'];
    $headers = "FROM: \"Title Here\" <glaanieboy@gmail.com>";
    if (mail($email,"Registration mail for ".$settings_fetch['title'],$mail_body,$headers)){
    //Rest of code here
Doesn't work. I also added \r\n right after the last >, but it just doesn't work. Back to -f then :(
 
write your own mailer that uses smtp. A lot easier and it is gauranteed to work.
 
Code:
<?php

// $Id: mailer.inc.php,v 1.9 2004/10/09 00:25:32 xistence Exp $
// -----------------------------------------------------------
// (C) 2002 - 2003 X-Istence.com
//
// Author: Jan-Willem Regeer
//         [email]xistence@x-istence.com[/email]
// -----------------------------------------------------------

// X-Istence.com Mailer Class 

class XI_Mailer { 
        private $to; 
        private $from; 
        private $header; 
        private $message; 
        private $data; 
        private $data_orig; 
        
        var $server_adress      = "localhost";
        var $server_port        = "25";
        var $server_username    = "";
        var $server_password    = "";
        
        function to($to) { 
                if(issarray($to) {
                        $this->to = $to; // Has to be an array.
                }
                else 
                        die("What kind of coding are you doing?"); 
        } 
        
        function from ($from) { 
                $this->from = $from; // Has to be a single adress 
        } 
        
        function subject($subject) { 
                $this->subject = $subject; 
        } 
        
        function mheader($custom = "") { 
                if ($custom == "") { 
                        $this->header  = "To: {email_name} <{email_usermail}>\r\n"; 
                        $this->header .= "From: {name} <{mail_from}>\r\n"; 
                        $this->header .= "Reply-To: {name} <{mail_from}>\r\n"; 
                        $this->header .= "Subject: {email_subject}\r\n"; 
                        $this->header .= "Return-Path: {name} <{mail_from}>\r\n";
                        $this->header .= "Bounce-To: {name} <{mail_from}>\r\n";
                        $this->header .= "Errors-To: {name} <{mail_from}>\r\n"; 
                        $this->header .= "X-Priority: 3\r\n"; 
                        $this->header .= "X-Mailer: X-Istence.com Mailer\r\n"; 
                } 
                else { 
                        $this->header = $custom; 
                } 
        } 
        
        function message ($message) { 
                $this->message = $message; 
        } 
        
        function send () { 
                $this->compile_entire(); 
        
                $connect = fsockopen ($this->server_adress , $this->server_port , $errno, $errstr, 5) or die("Mail server is down. Please hit your back button, and try again"); 
                $rcv = fgets($connect, 1024); 
                fputs($connect, "EHLO {$_SERVER['SERVER_NAME']}\r\n"); 
                $rcv = fgets($connect, 1024); 
        
                $x = count($this->to); 
        
                for ($y = 0; $y < $x; $y++) { 
                        $stuff['name']              = $this->from['name']; 
                        $stuff['mail_from']         = $this->from['mail']; 
                        $stuff['email_name']        = $this->to[$y]['email_name']; 
                        $stuff['email_usermail']    = $this->to[$y]['email_usermail']; 
                        $stuff['email_subject']     = $this->subject; 
                
                
                        fputs($connect, "MAIL FROM: ". $this->from['name'] ." <". $this->from['mail'] .">\r\n"); 
                        $rcv = fgets($connect, 1024); 
                        fputs($connect, "RCPT TO: ". $this->to[$y]['email_name'] ." <". $this->to[$y]['email_usermail'] .">\r\n"); 
                        $rcv = fgets($connect, 1024); 
                        fputs($connect, "DATA\r\n"); 
                        $rcv = fgets($connect, 1024); 
                        fputs($connect, preg_replace("/\{(.+?)\}/e", "\$stuff['\\1']", $this->data)); 
                        fputs($connect, ".\r\n"); 
                        $rcv = fgets($connect, 1024); 
                        fputs($connect, "RSET\r\n"); 
                        $rcv = fgets($connect, 1024); 
                } 
        
                fputs($connect, "QUIT\r\n"); 
                $rcv = fgets($connect, 1024); 
                fclose($connect); 
        
        } 
        
        function compile_entire() { 
                $this->data  = $this->header; 
                $this->data .= "\r\n"; 
                $this->data .= $this->message; 
                $this->data .= "\r\n"; 
        } 
} 
?>

I'll leave it up to you to figure out how to make it do its magic :).
 
here is a sample:

Code:
				$to['0']['email_name']          = chop($_POST['username']);
				$to['0']['email_usermail']      = chop($_POST['email']);
				$from['name']                   = "X-Istence.com";
				$from['mail']                   = "register-bounce@x-istence.com";

				$message  = "Thank You for Registering\r\n";
				$message .= "\r\n";
				$message .= "Your Information:\r\n";
				$message .= "Username: ". chop($_POST['username']) ."\r\n";
				$message .= "Password: ". chop($_POST['password']) ."\r\n";
				$message .= "\r\n\r\nPlease copy and paste or click the link below to activate your account:\r\n";
				$message .= "http://x-istence.com/activate.php?email=". chop($_POST['email']) ."&rid=". chop($_POST['activate_rid']) ."\r\n";
				$message .= "\r\n\r\nIf you did not request an account at X-Istence.com, please do not reply or click the link above.\r\n";
				$message .= "Your email adress will be deleted from the database within the next 24 hours.\r\n";
				$message .= "\r\n\r\n-- X-Istence.com Register Bot\r\n";

				require("./includes/mailer.inc.php");
				$mail = new XI_mailer;
				$mail->to($to);
				$mail->from($from);
				$mail->subject("X-Istence.com Registering Activation");
				$mail->mheader();
				$mail->message($message);
				$mail->send();

That should help you along. Might want to put a Date: date() (Read PHP.net for the proper variable you need to make it email compatible) in the header some place, but besides that it is fully usable.
 
Oh, I see, you directly send commands to the SMTP server, clever. Thank you bigtime for the code, I'll have a play with it and tell you the results. Thanks again!
 
Off course it is clever, no more screwing around with php mail() and getting that to work.
 
BUt one thing I am worried about, is it guaranteed to work with every SMTP server? In other words, are these standard commands? Also, can you send attachments using the function you created.
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,623
Latest member
AndersonLo
Back