Page 1 of 1

SwiftMailer instead of mail()

Posted: Mon Sep 18, 2006 9:36 am
by Ilija Studen
Hi,

Script I made has two modes for mailing. First (default one) will use settings from php.ini to send emails through SwiftMailer. Second one requires user to provide a valid SMTP server. Idea was to make things work out of the box for people who have properly configured mailing in PHP but at the same time to provide more power to people who need it. I've skipped mail() because script usualy needs to send multiple emails at once...

SMTP is working wihout any problems, but code I wrote that reads config from php.ini doesn't (script tries to send email and hangs until execution time is reached). Code:

Code: Select all

$sendmail_path = ini_get('sendmail_path');
if($sendmail_path) {
  return new Swift(new Swift_Sendmail_Connection($sendmail_path)); // use sendmail
} else {
  return new Swift(new Swift_SMTP_Connection(ini_get('SMTP'), ini_get('smtp_port'))); // use SMTP
} // if
What am I doing wrong here? Should this work?

Thanks!

Posted: Mon Sep 18, 2006 10:30 am
by Weirdan
try this

Code: Select all

$sendmail_path = ini_get('sendmail_path');
var_dump('sendmail_path', $sendmail_path); //gonna use sendmail binary
if($sendmail_path) {
  var_dump('gonna use sendmail binary');
  return new Swift(new Swift_Sendmail_Connection($sendmail_path)); // use sendmail
} else {
  var_dump('gonna use smtp connection');
  var_dump('Server:', ini_get('SMTP'), 'Port:', ini_get('smtp_port'));
  return new Swift(new Swift_SMTP_Connection(ini_get('SMTP'), ini_get('smtp_port'))); // use SMTP
}
and tell us what it spits at you

Posted: Mon Sep 18, 2006 10:56 am
by Ilija Studen
SMTP on Windows is working (reads host and port from the php.ini), but Sendmail fails on FreeBSD hosting (mail() is working without any problem). It just hangs...

On FreeBSD server I have a simple test file:

Code: Select all

<?php
  var_dump($sendmail_path = ini_get('sendmail_path'));
?>
Output:
string(25) "/usr/sbin/sendmail -t -i "