• problem figuring out why mail fails

    From bill@21:1/5 to All on Tue Apr 13 11:22:52 2021
    I have a script that sends mail in a loop. Unfortunately it is
    sending only the first.
    Mail returns "false" for all sends after the first:

    Here is the script segment:

    $to ='william@xxxx.com';
    $subject ='IRWOM Status Update request';

    $headers[] = 'MIME-Version: 1.0';
    $headers[] = 'Content-type: text/html; charset=iso-8859-1';
    $headers[] = 'From: michigan@xxxxx.org';
    // Mail it

    $sent =mail($to, $subject, $message, implode("\r\n", $headers));

    //debug info
    echo "sent:" . var_dump($sent);

    echo basename(__FILE__) . ": " . __LINE__ . ": $appNum<br />";
    print_r (error_get_last());
    echo "<br />";
    -------------------------

    var_dump ($sent) returns bool(false)
    error_get_last returns nothing rather than the array expected
    If I put an intentional error above the send error_get_last
    correctly reports that.

    Does anyone see anything that would generate this or have any
    suggestions for debugging the mail send?

    here is the debugging output:
    -------------------
    statusCheckGenerate.php: 160:
    to: william@xxxxx.com
    headers: MIME-Version: 1.0
    Content-type: text/html; charset=iso-8859-1
    From: michigan@xxxxxx.org
    bool(true) sent:

    statusCheckGenerate.php: 160:
    to: william@xxxxxxn.com
    headers: MIME-Version: 1.0
    Content-type: text/html; charset=iso-8859-1
    From: michigan@xxxxxxx.org
    MIME-Version: 1.0
    Content-type: text/html; charset=iso-8859-1
    From: michigan@xxxxx.org
    bool(false) sent:


    -bill

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jeroen Belleman@21:1/5 to bill on Tue Apr 13 21:01:23 2021
    On 2021-04-13 17:22, bill wrote:
    I have a script that sends mail in a loop. Unfortunately it is sending only the first.
    Mail returns "false" for all sends after the first:

    Good! We don't want anyone sending mail in a loop. We have
    quite enough of that already.

    Jeroen Belleman

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J.O. Aho@21:1/5 to bill on Tue Apr 13 22:05:20 2021
    On 13/04/2021 17.22, bill wrote:
    I have a script that sends mail in a loop.  Unfortunately it is sending
    only the first.
    Here is the script segment:

    As you don't have the whole code, it's just a guess when it comes to the problem. I would guess it's your headers that grows for each mail you
    try to send, also simpler to use an array with named cells, see php.net documentation.


    Mail returns "false" for all sends after the first:
    error_get_last returns nothing rather than the array expected

    There ain't any direct error in the PHP code, so error_get_last will not generate anything related to this, the false just indicates that the
    mail server rejected your mail for an unknown reason. Also keep in mind
    that true don't mean that the mail was sent, just that the mail server
    didn't throw an error.


    Please do not make this as a public web page as email sending tend to be
    a lot more to do than use the mail-function, you need to verify that all
    the data is in correct format, as it's simple to make header injections
    and your web page would then used by spammers until your web host kicks
    you out after the web server appears on blacklists.
    Also remember to not send mail to people who hasn't agreed on getting
    mail from you, you may otherwise commit a crime in multiple jurisdictions.


    --

    //Aho

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to bill on Tue Apr 13 21:08:44 2021
    On Tue, 13 Apr 2021 11:22:52 -0400, bill wrote:

    I have a script that sends mail in a loop. Unfortunately it is
    sending only the first.
    Mail returns "false" for all sends after the first:

    Here is the script segment:

    $to ='william@xxxx.com';
    $subject ='IRWOM Status Update request';

    $headers[] = 'MIME-Version: 1.0';
    $headers[] = 'Content-type: text/html; charset=iso-8859-1';
    $headers[] = 'From: michigan@xxxxx.org';
    // Mail it

    $sent =mail($to, $subject, $message, implode("\r\n", $headers));

    //debug info
    echo "sent:" . var_dump($sent);

    echo basename(__FILE__) . ": " . __LINE__ . ": $appNum<br />"; print_r (error_get_last());
    echo "<br />";
    -------------------------

    var_dump ($sent) returns bool(false)
    error_get_last returns nothing rather than the array expected
    If I put an intentional error above the send error_get_last
    correctly reports that.

    Does anyone see anything that would generate this or have any
    suggestions for debugging the mail send?

    here is the debugging output:
    -------------------
    statusCheckGenerate.php: 160:
    to: william@xxxxx.com
    headers: MIME-Version: 1.0
    Content-type: text/html; charset=iso-8859-1
    From: michigan@xxxxxx.org
    bool(true) sent:

    statusCheckGenerate.php: 160:
    to: william@xxxxxxn.com
    headers: MIME-Version: 1.0
    Content-type: text/html; charset=iso-8859-1
    From: michigan@xxxxxxx.org
    MIME-Version: 1.0
    Content-type: text/html; charset=iso-8859-1
    From: michigan@xxxxx.org
    bool(false) sent:

    If you examine the dump (above) from the failing message,
    you will note that the message contains:
    - two (2) "MIME-Version:" headers,
    - two (2) "Content-type:" headers, and
    - two (2) "From:" headers

    I have no doubt that the php mail() function will get confused
    with the duplicated headers.

    I suspect that you do not clear your $headers[] array between emails,
    causing each email to /append/ it's headers to the (growing) header
    list.

    Try adding
    unset($headers);
    after your
    $sent = mail($to, $subject, $message, implode("\r\n", $headers));


    HTH
    --
    Lew Pitcher
    "In Skills, We Trust"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arno Welzel@21:1/5 to All on Wed Apr 14 16:32:40 2021
    bill:

    I have a script that sends mail in a loop. Unfortunately it is
    sending only the first.
    Mail returns "false" for all sends after the first:

    Here is the script segment:

    $to ='william@xxxx.com';
    $subject ='IRWOM Status Update request';

    $headers[] = 'MIME-Version: 1.0';
    $headers[] = 'Content-type: text/html; charset=iso-8859-1';
    $headers[] = 'From: michigan@xxxxx.org';

    If you do this in a loop you all ADD headers with every loop cycle.

    Better do this:

    $headers = [
    'MIME-Version: 1.0',
    'Content-type: text/html; charset=iso-8859-1',
    'From: michigan@xxxxx.org',
    ];

    [...]
    here is the debugging output:
    -------------------
    statusCheckGenerate.php: 160:
    to: william@xxxxx.com
    headers: MIME-Version: 1.0
    Content-type: text/html; charset=iso-8859-1
    From: michigan@xxxxxx.org
    bool(true) sent:

    statusCheckGenerate.php: 160:
    to: william@xxxxxxn.com
    headers: MIME-Version: 1.0
    Content-type: text/html; charset=iso-8859-1
    From: michigan@xxxxxxx.org
    MIME-Version: 1.0
    Content-type: text/html; charset=iso-8859-1
    From: michigan@xxxxx.org
    bool(false) sent:

    Don't you see that the second mail has every header twice?

    This is because of the reason I explained above.

    Don't get me wrong - but at this experience level you should not create
    scripts which send e-mails at all. By sending a lot of e-mails this way
    your provider or hoster will soon be blocked because of outgoing spam
    from his network. You also need to check how many e-mails per hour are acceptable for your hoster/provider and you also need to add certain
    headers to indicate that the e-mails are either transactional or
    originate from a subscriber list.

    Maybe using a service like Mailjet, Sendinblue, smtp2go etc. and the
    respective API of these services is the better choice for you.

    --
    Arno Welzel
    https://arnowelzel.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jerry Stuckle@21:1/5 to Arno Welzel on Wed Apr 14 12:58:17 2021
    On 4/14/2021 10:32 AM, Arno Welzel wrote:
    bill:

    I have a script that sends mail in a loop. Unfortunately it is
    sending only the first.
    Mail returns "false" for all sends after the first:

    Here is the script segment:

    $to ='william@xxxx.com';
    $subject ='IRWOM Status Update request';

    $headers[] = 'MIME-Version: 1.0';
    $headers[] = 'Content-type: text/html; charset=iso-8859-1';
    $headers[] = 'From: michigan@xxxxx.org';

    If you do this in a loop you all ADD headers with every loop cycle.

    Better do this:

    $headers = [
    'MIME-Version: 1.0',
    'Content-type: text/html; charset=iso-8859-1',
    'From: michigan@xxxxx.org',
    ];

    Or, since he's not changing the headers, just set $headers once before
    entering the loop. The same with $subject if that doesn't change.

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    jstucklex@attglobal.net
    ==================

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From bill@21:1/5 to J.O. Aho on Fri Apr 16 08:33:39 2021
    On 4/13/2021 4:05 PM, J.O. Aho wrote:
    On 13/04/2021 17.22, bill wrote:
    I have a script that sends mail in a loop.  Unfortunately it is
    sending only the first.
    Here is the script segment:



    As you don't have the whole code, it's just a guess when it comes
    to the problem. I would guess it's your headers that grows for
    each mail you try to send, also simpler to use an array with
    named cells, see php.net documentation.


    Thank you to J.O Aho and Lew Pitcher and Arno Weizel and Jerry
    Stuckle.

    I moved the header setting out of the loop and all is good. Many
    thanks.
    -bill

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kristall@21:1/5 to bill on Mon Feb 27 02:40:27 2023
    Aitaksite mind natuke rahaga ?

    Asun Männimäe 27-39, Viljandi, EESTI RIIK.


    Telefon: (+372) 56091196




    On Friday, April 16, 2021 at 2:33:48 PM UTC+2, bill wrote:
    On 4/13/2021 4:05 PM, J.O. Aho wrote:
    On 13/04/2021 17.22, bill wrote:
    I have a script that sends mail in a loop. Unfortunately it is
    sending only the first.
    Here is the script segment:



    As you don't have the whole code, it's just a guess when it comes
    to the problem. I would guess it's your headers that grows for
    each mail you try to send, also simpler to use an array with
    named cells, see php.net documentation.

    Thank you to J.O Aho and Lew Pitcher and Arno Weizel and Jerry
    Stuckle.

    I moved the header setting out of the loop and all is good. Many
    thanks.
    -bill

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kristall@21:1/5 to Jerry Stuckle on Mon Feb 27 02:40:40 2023
    Aitaksite mind natuke rahaga ?

    Asun Männimäe 27-39, Viljandi, EESTI RIIK.


    Telefon: (+372) 56091196



    On Wednesday, April 14, 2021 at 6:58:30 PM UTC+2, Jerry Stuckle wrote:
    On 4/14/2021 10:32 AM, Arno Welzel wrote:
    bill:

    I have a script that sends mail in a loop. Unfortunately it is
    sending only the first.
    Mail returns "false" for all sends after the first:

    Here is the script segment:

    $to ='wil...@xxxx.com';
    $subject ='IRWOM Status Update request';

    $headers[] = 'MIME-Version: 1.0';
    $headers[] = 'Content-type: text/html; charset=iso-8859-1';
    $headers[] = 'From: mich...@xxxxx.org';

    If you do this in a loop you all ADD headers with every loop cycle.

    Better do this:

    $headers = [
    'MIME-Version: 1.0',
    'Content-type: text/html; charset=iso-8859-1',
    'From: mich...@xxxxx.org',
    ];

    Or, since he's not changing the headers, just set $headers once before entering the loop. The same with $subject if that doesn't change.

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    jstu...@attglobal.net
    ==================

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)