"/usr/sbin/sendmail" not working with SwiftMailer

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
pardalito
Forum Newbie
Posts: 5
Joined: Wed Feb 14, 2007 8:19 am

"/usr/sbin/sendmail" not working with SwiftMailer

Post by pardalito »

Hi,

I using SwiftMailer 2.1.7 PHP4.
My host are blocking SMTP connections and php mail() is not a good solution.
I try to send email by sendmail (/usr/sbin/sendmail), but it doesnt work.

SCRIPT:

Code: Select all

<?php
require('./Swift/Swift.php');
require('./Swift/Connection/Sendmail.php');

$connection = new Swift_Connection_Sendmail(SWIFT_AUTO_DETECT);
$mailer = new Swift($connection);

//If anything goes wrong you can see what happened in the logs
if ($mailer->isConnected())
{
	//Sends a simple email
	$mailer->send(
		'"RASP" <tt@tt.es>',
		'"Newsletter" <tt@tt.es>',
		'Some Subject',
		"Hello Joe it's only me!"
	);
	//Closes cleanly... works without this but it's not as polite.
	$mailer->close();
}

echo "The mailer failed to connect. Errors: <pre>".print_r($mailer->errors, 1)."</pre><br />
	Log: <pre>".print_r($mailer->transactions, 1)."</pre>";

?>
LOG:
The mailer failed to connect. Errors:
Array
(
[0] => Array
(
[num] => -1
[time] => 0.06903200 1171463068
[message] => Send Error: Sending to 1 recipients rejected (bad response code).
)
)

LOG
Array
(
[0] => Array
(
[command] =>
[time] => 0.03933100 1171463068
[response] => 220 cgi00-ch.uk.clara.net ESMTP Exim 4.52 Wed, 14 Feb 2007 14:24:28 +0000
)
[1] => Array
(
[command] => EHLO http://www.movilquick.net
[time] => 0.05049900 1171463068
[response] => 250-cgi00-ch.uk.clara.net Hello web57990 at http://www.movilquick.net
250-SIZE 52428800
250-PIPELINING
250 HELP
)
[2] => Array
(
[command] => MAIL FROM:
[time] => 0.05136600 1171463068
[response] => 250 OK
)
[3] => Array
(
[command] => RCPT TO:
[time] => 0.05148800 1171463068
[response] => 550 Administrative prohibition
)
[4] => Array
(
[command] => RSET
[time] => 0.06893100 1171463068
[response] => 250 Reset OK
)
[5] => Array
(
[command] => QUIT
[time] => 0.06914100 1171463068
[response] => 221 cgi00-ch.uk.clara.net closing connection
)
)
I try the PHPMailer in sendmail mode, and it send emails without errors.

SCRIPT:

Code: Select all

function SendmailSend($header, $body) {
        if ($this->Sender != "")
            $sendmail = sprintf("%s -oi -f %s -t", $this->Sendmail, $this->Sender);
        else
            $sendmail = sprintf("%s -oi -t", $this->Sendmail);
 
        if(!@$mail = popen($sendmail, "w"))
        {
            $this->SetError($this->Lang("execute") . $this->Sendmail);
            return false;
        }
 
        fputs($mail, $header);
        fputs($mail, $body);
 
        $result = pclose($mail) >> 8 & 0xFF;
        if($result != 0)
        {
            $this->SetError($this->Lang("execute") . $this->Sendmail);
            return false;
        }
 
        return true;
    }
I prefer SwiftMailer, so anyone can help me??

Sorry my bad, bad, bad, English.

Thanks.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Your host have disabled sendmail. Speak to them ;) It appears they only have it set up to take email in, not send it.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

PS: That code that sent without errors, did it actually send? Sendmail running in -t mode doesn't give you any feedback so the only time it will generate errors is if something has gone badly wrong. -t mode basically feeds the email straight in, skipping the SMTP protocol initial stage. SwiftMailer v3 has "experimental" sendmail -t support:

Code: Select all

$swift =& new Swift(new Swift_Connection_Sendmail("/usr/sbin/sendmail -t"));
However, the reason I say experimental is because it's not been tested much due to known issues with MTA compliancy handling Bcc addresses. Because it avoids SMTP, some MTAs deal with Bcc differently.... the "expected" behaviour would be to make the MUA handle Bcc itself, but some MTAs actually try doing it... Exim mentions in it's documentation that it's not fully supported because of this Bcc issue. I may support it officially in future, but for now, running in -bs mode works fast anyway - and you get the feedback.
pardalito
Forum Newbie
Posts: 5
Joined: Wed Feb 14, 2007 8:19 am

Post by pardalito »

Hi,

Frist of all, thanks for the reply :P.

My admin server said:
- Sendmail is active and working...
- Sendmail path: /usr/sbin/sendmail
- Commands: -t -i
- Perl and PHP libs supported.
That code that sent without errors, did it actually send?
- No. Nothing :cry:

Swift 2.1.7 PHP 4:

Code: Select all

... set_time_limit(120); ...
... Swift_Connection_Sendmail("/usr/sbin/sendmail -t") ...
Result: Server Timeout

I will try with Swift v3 PHP 4.

Best regards,
Pardalito.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

-t doesn't work with Swift 2. You need version 3 as stated in my last post. Release candidates appear on the home page. Like I say... you won't get any support from me for it though -- sorry ;)
My admin server said:
- Sendmail is active and working...
Maybe, but not in SMTP (-bs) mode. It's also odd that your email didn't send with PhpMailer. Who's your host if you don't mind me asking? I like to keep track of how different shared hosts restrict mailing ability for obvious reasons.
pardalito
Forum Newbie
Posts: 5
Joined: Wed Feb 14, 2007 8:19 am

Post by pardalito »

Hi,

With Swift v3 PHP4:

Code: Select all

<?php

require_once "lib/Swift.php";
require_once "lib/Swift/Connection/Sendmail.php";

//Start Swift
$swift =& new Swift(new Swift_Connection_Sendmail("/usr/sbin/sendmail -t"));

//Create the message
$message =& new Swift_Message("My subject", "My body");

//Now check if Swift actually sends it
if ($swift->send($message, new Swift_Address("tt@tt.es", "RASP"), new Swift_Address("tt@tt.es", "SAT"))) echo "Sent";
else echo "Failed";

?>
Works!!!!!!!!!!!!!!!! :P :P :P
But the provider always mark the mail as SPAM (SPAM: My subject)
With PHPMailer dont mark the mail as SPAM.
It's also odd that your email didn't send with PhpMailer.
With PHPMailer works and send email...
Who's your host if you don't mind me asking?
Service provider: http://www.amen.es (very bad provider)
Host: http://www.movilquick.net
PHP Info: http://www.movilquick.net/phpinfo.php

I will waiting for Swift v3...

Thanks.

Best Regards,
Pardalito.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I think I know what will cause it to be marked as spam. I need more than just -t otherwise it will appear as if "nobody" or "root" or "www-data" sent the email in the headers. I can look at implementing support further in future releases, but for now, I'm not adding feature-creep until I've got the RC's to full versions... looks like that'll happen very soon :)

PS: You can use the NativeMail connection. If you're on a linux machine it will be just about as fast as sendmail -t.
pardalito
Forum Newbie
Posts: 5
Joined: Wed Feb 14, 2007 8:19 am

Post by pardalito »

Thanks :P

Thanks :P

Thanks :P

Best Regards,
Pardalito
pardalito
Forum Newbie
Posts: 5
Joined: Wed Feb 14, 2007 8:19 am

Post by pardalito »

Hi,
PS: You can use the NativeMail connection.
PHP mail() is limited. My host only permit 150 PHP mail() sends per day.

I have 254 users in my newsletter with personalized mail.

I need to send 254 PHP mail().

I will wait for Swift v3 PHP4.

Best Regards,
Pardalito.
Post Reply