[thelist] PHP Mail() function

Renoir B. renoirb at gmail.com
Sun Jul 20 12:54:49 CDT 2014


Hi all,

Sending email is something simple and very complex in the same time.

I surprised almost none of this has been mentioned.

A few hints:

1.  Have a database table with full email body ready to send.  No loops,
just raw dump plus flags if it had been sent.

2.  If you can do SSH, do tests with swaks.  It helps testing various email
routes

3.  Use Swift mailer.

It allows to create mail queues in a temp folder --no need for a database--
it also allows to configure email gateways and send emails in a separate
worker (e.g cron job)

4.  If you aren't into servers and stop worrying.

Use specialized ervices such as mailgun, mailchimp, etc.  You wont have to
worry again, plus it gives mail open rates and analytics

Regards,

Renoir Boulanger

https://renoirboulanger.com/  ✪  @renoirb
~
On Jun 3, 2014 9:50 AM, "Bob Meetin" <bobm at dottedi.biz> wrote:

> Nothing in your code, certainly not
>
> $body .= "\n\n\n";
>
> looks wrong. Any idea why it started working again, a couple days later?
> How or why is it resetting, overnight? I can't imagine that you reached a
> limits threshhold. For you to have hit even a limit as low as 50/hour you
> need to be able to type/test incredibly fast.
>
> To dispel any limits doubt you could run a simple foreach loop of, say 150
> iterations, and have it email a simple test (not your code).  You could
> even dump the message count in the subject line. And check with support.
> Support typically does not support your scripting, but sometimes you get a
> tech is bored and curious.
>
> Server and email logs are above webroot, /home/$your_account/logs
> (probably) and /home/$your_account/mail
>
> If you are logged in and at the command line, you can look for typical
> server/php errors:
>
> % find . -name error_log -print
>
> php error reporting - maybe this will help - http://stackoverflow.com/
> questions/1053424/how-do-i-get-php-errors-to-display
>
>
>
> On 06/03/2014 03:30 AM, Santilal Parbhu wrote:
>
>> Hi
>>
>> I have been tied up with other things for a few days and have not been
>> able
>> to work on this job.  However, I'm back on it now.
>>
>> Where do I find these logs.  I have had a look but could not find them.
>>  Do
>> I have to request them from my hosting provider?
>>
>> I am building up my message using a variable $body.  I initialise this to
>>
>> $body = "";
>>
>> Then I add to the message using
>>
>> $body .= "new string";
>>
>> $body .= "another new string";
>>
>> And so on.
>>
>> Eventually I send the email using
>>
>> mail($to,$subject,$body,$headers);
>>
>> I went through and disabled all of the "$body .=" instructions and then
>> re-enabled them one at a time.  When I got the following line
>>
>> $body .= "\n\n\n";
>>
>> the email failed.  So then I thought there must be something in this line
>> that is causing the mail to fail.  So I disabled this line again by
>> commenting it out and resent the mail expecting it to work.  However, it
>> did
>> not.  So now I am thinking it is not my code but something on the server
>> side so perhaps it is the logs that hold the only clue.
>>
>> Thanks everyone for your help.
>>
>> Santilal
>>
>> Santilal Parbhu
>> Scorpion Engineering Limited
>> PO Box 171
>> Alexandra
>> Phone: +64 3 440 2100
>> Mobile: +64 21 2655991
>> Email: santilal at scorpioneng.co.nz
>> Web: www.scorpioneng.co.nz
>>
>> -----Original Message-----
>> From: thelist-bounces at lists.evolt.org
>> [mailto:thelist-bounces at lists.evolt.org] On Behalf Of Bob Meetin
>> Sent: Sunday, 1 June 2014 3:13 a.m.
>> To: thelist at lists.evolt.org
>> Subject: Re: [thelist] PHP Mail() function
>>
>> Hmm, and if the error or mail logs are not giving you anything meaningful,
>> you can probably add a few lines of code to your php script using fopen
>> and
>> fwrite to create your own text logfile. You could also dabble and change
>> the
>> script to pull a couple different lines for tests. Eliminate one variable
>> at
>> a time.
>>
>> <?php
>>
>> $datetime = date('Y-m-d-H-i-s');
>>
>> $text --> maybe some output from the query, up to you
>>
>> if ( some_condition ) // optional
>> {
>>     $logfile = "$path/log.txt";
>>     $fpi = fopen("$logfile", "a"); // a to append
>>     fwrite($fpi, "$datetime|$text|$text2\n");
>>     fclose ($fpi);
>> }
>>
>> ?>
>>
>> On 05/31/2014 08:58 AM, Hassan Schroeder wrote:
>>
>>> On Fri, May 30, 2014 at 4:25 PM, Santilal Parbhu
>>> <santilal at scorpioneng.co.nz> wrote:
>>>
>>>  Hey thanks for the help.  However, I have found that I am barking up
>>>> the wrong tree.  I inserted a test script and found that it worked.
>>>> So then I disabled everything in my script that accesses the database
>>>> and essentially just left the mail() part.  This also worked.  So
>>>> there must be something in the data that I select that is stopping
>>>> the email going out.  Perhaps a control character or similar.  Is this
>>>>
>>> possible.
>>
>>> Anything's possible :-)
>>>
>>> However, to repeat: what's in the logs? If mail sending is failing due
>>> to some charset/encoding issue, I would expect to see that logged.
>>>
>>> Actual data from your environment trumps guessing in most cases...
>>>
>>>
>> --
>> Bob Meetin
>> www.dottedi.biz
>> 303-926-0167 (m)
>>
>>
>
> --
> Bob Meetin
> www.dottedi.biz
> 303-926-0167 (m)
>
> --
>
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !


More information about the thelist mailing list