0

There are no errors in my code from what I can find and my local ssmpt client is configured and I can send mail via the command line. But no mail and no error come from php at all. It's as though php never hits this local mailer. I 'do' have my sendmail path set in my php.ini and restarted apache. I don't know what else it could be?

<?php
require_once('config.php');
$attrs = array(PDO::ATTR_PERSISTENT => true);
$pdo = new PDO("mysql:host=localhost;dbname=".$dbname, $db_username, $db_password, $attrs);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$custlist = $pdo->prepare("SELECT customer_list.sms_num, carriers.carrieraddr, customer_list.contact_first,  customer_list.contact_last
    FROM carriers, customer_list
    WHERE send_id=send_code
    ORDER BY customer_list.sms_num");
#$carrierlist = $pdo->prepare("SELECT * FROM carriers");
if (isset($_POST['body'], $custlist)) {
    $custlist->execute();
    #var_dump($custlist);
    #var_dump($_POST['body']);
    while ($row = $custlist->fetch(PDO::FETCH_ASSOC)) {
        #$prefix = $row['sms_num'];
        #$suffix = $row['carrieraddr'];
        $to = 'brads@telecomm.com';
        $subject = 'the subject';
        $message = 'hello';
        $headers = 'From: admin@telecomm.com' . "\r\n" .
            'Reply-To: admin@telecomm.com' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();

        mail($to, $subject, $message, $headers);
        #$body = $_POST['body'];

        #var_dump($prefix);
        #var_dump($suffix);
        #var_dump($_POST['body']);
    }
}

//$products = array();
$smscustobject = new ArrayObject($custlist);
#$smsarrayobject = new ArrayObject($carrierlist);

$pdo = null;
?>
<form action="" method="POST">
    Your Message Body <input name="body" type="text" />
    <input type="submit">
</form>
brad
  • 870
  • 2
  • 13
  • 38
  • You email arrives to spam box, did you check it? – Wiggler Jtag Aug 16 '13 at 10:35
  • @Wiggler Jtag nope, no junk mail. but a little more digging reveals that that php appears to be trying to use mod_mail for apache instead of ssmtp. This will never work, all of my smtp settings are in ssmtp and not apache. apache2: mail() on [/home/downlowd/www/dev/campaignLaunch.php:25]: To: brads@telecomm.com -- Headers: From: admin@telecomm.com – brad Aug 16 '13 at 10:46
  • Ah, then cant help you, this is server config and I am using nginx instead of apache. Wish the problem was on php side... So now for sure u can find the answer on google and Im sure there are ssmtp x apache configs. – Wiggler Jtag Aug 16 '13 at 10:52
  • @Wiggler Jtag My php.ini http://www.bpaste.net/show/6fijml3QQbOVFytdo9QM/ – brad Aug 16 '13 at 10:53
  • Btw. one question, u're sending it through dedicated SMTP mail.nyctelecomm.com, why dont you simple use PHP Pear mail? Or its your own SMTP server? – Wiggler Jtag Aug 16 '13 at 10:58
  • changing the sendmail path to /usr/sbin/ssmtp didn't help – brad Aug 16 '13 at 10:58

3 Answers3

1

I had the same problem and found after running a port testing PHP script that I needed to configure linux (Centos in my case) to allow httpd to access TCP ports using the following command on the command line:

setsebool httpd_can_network_connect=1

or permanently by

setsebool -P httpd_can_network_connect=1

NB: using the -P option took over 2 minutes on my machine so be patient

Hey presto! my mail command worked.

My situation was that I was able to send mail to my ISP's SMTP Server ie mail.optusnet.com.au Port 25 from the command line but not using PHP scripts ran in my browser.

Also, ensure that your firewall is not interfering with PHP by running a Telnet session to you SMTP host.

eg $telnet mail.optusnet.com.au 25

In your case I suspect not as you are able to send emails from the Command Line.

I hope that helps

Mark
  • 166
  • 1
  • 13
0

I'd personally go for something like SwiftMailer - it is updated regularly and is relatively simple to get going http://swiftmailer.org/

Zabs
  • 13,852
  • 45
  • 173
  • 297
0

Removing the sendmail path and allowing the system to use defaults fix it.

brad
  • 870
  • 2
  • 13
  • 38