ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

PHP Community - Can I send mails?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP Community - Can I send mails?

    As a PHP and iSeries enthusiast, I recently succeded to install and run PHP Community via yum/rpm in an existing apache instance.
    Everything works fine, even ODBC->DB2 data read... I was very happy, until I found out I can't send emails with any of the methods I knew.
    When I try to use mail() function (smtp server is internal and without authentication, already configured in php.ini), it simply returns false.
    This is the apache log:
    sh: -t: not found
    So I found out that sendmail command is not present in the system, and not even available in the repository packages.
    Also, the only other method to send mails I knew (Pear) is not installed with PHP Community and neither is available.
    Am I doing something wrong or there's no chance for me to send emails from php?

  • #2
    We use PHP to send out emails all the time. We use PHPMailer (https://github.com/PHPMailer/PHPMailer) and it works very well.

    Comment


    • garetjax76
      garetjax76 commented
      Editing a comment
      Many thanks, I didn't knew PHPMailer. It works perfectly.

  • #3
    So have you tried the suggestion I made to @garetjax76 - it seemed to work for him.

    Comment


    • #4
      Originally posted by JonBoy View Post
      So have you tried the suggestion I made to @garetjax76 - it seemed to work for him.
      I confirm. I downloaded PHPMailer, put it on my IFS and wrote this simple wrapper function in order to simplify the mailing process:
      PHP Code:
      <?php
      use PHPMailer\PHPMailer\PHPMailer;
      use 
      PHPMailer\PHPMailer\Exception;
      use 
      PHPMailer\PHPMailer\SMTP;

      require 
      'phpmailer/Exception.php';
      require 
      'phpmailer/PHPMailer.php';
      require 
      'phpmailer/SMTP.php';

      function 
      my_sendmail($address_to$subject$html_body$attachment_url '') {
      $mail = new PHPMailer;
      $mail->isSMTP();
      $mail->SMTPDebug SMTP:DEBUG_OFF;
      $mail->Host 'your.smtp.server';
      $mail->Port 25;
      $mail->setFrom('from@yourdomain.com''IBM i');
      $mail->addAddress($address_to$address_to);
      $mail->Subject $subject;
      $mail->msgHTML($html_body);
      $mail->addAttachment($attachment_url);
      return 
      $mail->send();
      }

      Comment


      • #5
        For the sake of completeness - I should have mentioned earlier that if you get the Community edition from Alan Seiden at https://www.seidengroup.com/free-com...php-for-ibm-i/ you'll get a version with all of the commonly needed functions like email etc. pre-built. Highly recommended and their instructions for install etc. are excellent.

        Comment

        Working...
        X