Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #18608
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: problem figuring out why mail fails |
| Date | 2021-04-13 21:08 +0000 |
| Organization | The Pitcher Digital Freehold |
| Message-ID | <s5518s$lpk$1@dont-email.me> (permalink) |
| References | <s54d0b$spc$1@gioia.aioe.org> |
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"
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web