Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #18605 > unrolled thread
| Started by | bill <william@TechServSys.com> |
|---|---|
| First post | 2021-04-13 11:22 -0400 |
| Last post | 2023-02-27 02:40 -0800 |
| Articles | 9 — 7 participants |
Back to article view | Back to comp.lang.php
problem figuring out why mail fails bill <william@TechServSys.com> - 2021-04-13 11:22 -0400
Re: problem figuring out why mail fails Jeroen Belleman <jeroen@nospam.please> - 2021-04-13 21:01 +0200
Re: problem figuring out why mail fails "J.O. Aho" <user@example.net> - 2021-04-13 22:05 +0200
Re: problem figuring out why mail fails bill <william@TechServSys.com> - 2021-04-16 08:33 -0400
Re: problem figuring out why mail fails Kristall <kristallin555@gmail.com> - 2023-02-27 02:40 -0800
Re: problem figuring out why mail fails Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-04-13 21:08 +0000
Re: problem figuring out why mail fails Arno Welzel <usenet@arnowelzel.de> - 2021-04-14 16:32 +0200
Re: problem figuring out why mail fails Jerry Stuckle <jstucklex@attglobal.net> - 2021-04-14 12:58 -0400
Re: problem figuring out why mail fails Kristall <kristallin555@gmail.com> - 2023-02-27 02:40 -0800
| From | bill <william@TechServSys.com> |
|---|---|
| Date | 2021-04-13 11:22 -0400 |
| Subject | problem figuring out why mail fails |
| Message-ID | <s54d0b$spc$1@gioia.aioe.org> |
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
[toc] | [next] | [standalone]
| From | Jeroen Belleman <jeroen@nospam.please> |
|---|---|
| Date | 2021-04-13 21:01 +0200 |
| Message-ID | <s54pq1$1bqj$1@gioia.aioe.org> |
| In reply to | #18605 |
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
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2021-04-13 22:05 +0200 |
| Message-ID | <idmbs0F7hq7U1@mid.individual.net> |
| In reply to | #18605 |
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
[toc] | [prev] | [next] | [standalone]
| From | bill <william@TechServSys.com> |
|---|---|
| Date | 2021-04-16 08:33 -0400 |
| Message-ID | <s5c074$gm0$1@gioia.aioe.org> |
| In reply to | #18607 |
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
[toc] | [prev] | [next] | [standalone]
| From | Kristall <kristallin555@gmail.com> |
|---|---|
| Date | 2023-02-27 02:40 -0800 |
| Message-ID | <05141489-10a1-41aa-8b78-e8b8eab58960n@googlegroups.com> |
| In reply to | #18611 |
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
[toc] | [prev] | [next] | [standalone]
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Date | 2021-04-13 21:08 +0000 |
| Message-ID | <s5518s$lpk$1@dont-email.me> |
| In reply to | #18605 |
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"
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2021-04-14 16:32 +0200 |
| Message-ID | <idoco8FjgsfU1@mid.individual.net> |
| In reply to | #18605 |
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
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2021-04-14 12:58 -0400 |
| Message-ID | <s576vg$6iu$1@jstuckle.eternal-september.org> |
| In reply to | #18609 |
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 ==================
[toc] | [prev] | [next] | [standalone]
| From | Kristall <kristallin555@gmail.com> |
|---|---|
| Date | 2023-02-27 02:40 -0800 |
| Message-ID | <0ccc4384-87e6-4dc9-a611-471c36aaeb7fn@googlegroups.com> |
| In reply to | #18610 |
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 > ==================
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web