SwiftMailer instead of mail()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Ilija Studen
Forum Newbie
Posts: 7
Joined: Thu Sep 07, 2006 10:58 am
Location: Novi Sad, Serbia

SwiftMailer instead of mail()

Post 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!
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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
User avatar
Ilija Studen
Forum Newbie
Posts: 7
Joined: Thu Sep 07, 2006 10:58 am
Location: Novi Sad, Serbia

Post 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 "
Post Reply