php mail issue?

Posted on 2013-10-15
Medium Priority
Last Modified: 2013-10-18
The following is a snippet of code from a php program that sends an email.

      $mailto = "redacted@hotmail.com, sales@redacted.com, kneff@redacted.com";
      $subj = "On-Line Invoice Payment";
      $totpmnt = 0;
      $body = "Customer $custname has made on on-line payment as follows:\n";
      for ($i = 0; $i < $ni; $i++) {
// fix this regarding "blank" invoice #
            if ($paids[$i] != "") {
                  $pdfmt = sprintf($paids[$i]);
                  $body = $body . "Invoice Number: $invnos[$i] - Payment Amount: \$$pdfmt\n";
                  $totpmnt = $totpmnt + $paids[$i];
      $totf = sprintf("%01.2f", $totpmnt);                  
      $body = $body . "\nThe total amount paid was: \$" . $totf. "\n";
      $header  = "MIME-Version: 1.0\r\n";
      $header .= "Content-type: text/html; charset=iso-8859-1\r\n";
      $header .= "From: donotreply@LSS.com\r\n";      
      $header .= "Cc: redacted@gmail.com\r\n";

      $mres = mail($mailto, $subj, $body, $header);

In a test this AM, I executed this code; I am the Cc at the end of $header. I received the email; see attached.

The recipient kneff@lawnsprinklerservices.com says she received the email; the others did not (they claim).

Subsequent to that, I manually composed an email to the 3 emails in the $mailto variable. It was received by all.

Is there anything wrong with the formatting that could be causing this failure?

Question by:Richard Korts
LVL 111

Expert Comment

by:Ray Paseur
ID: 39574368
Quite probably the email was put into the junk or spam folders.  Automatically generated email has a "smell" that most modern mail programs can detect.  You should tell them to white-list the sending domain and the sending "from" address.
LVL 84

Accepted Solution

Dave Baldwin earned 2000 total points
ID: 39574408
PHP mail() is kind of crippled.  And I would expect anything from 'donotreply', especially with multiple 'To:' addresses to be deleted by Hotmail.  Many mail services will not accept email from an address that can't be verified like 'donotreply@LSS.com'.

Your best option is to send individual emails to each recipient from a verifiable email address.  I don't know why you are sending invoices from a 'donotreply' anyway.  That isn't business-like to me.

LVL 31

Expert Comment

by:Marco Gasi
ID: 39574441
Personally, I use PhpMailer to send mutliple emails and it works fine. In addition is very well documented and you find several tutorial on the web.

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.


Author Comment

by:Richard Korts
ID: 39574443
To Dave Baldwin,

The specific email in question is being sent to email addresses at the company (not the customer) when a payment is made by a customer. But I will do exactly as you suggest.

LVL 84

Expert Comment

by:Dave Baldwin
ID: 39574473
The email servers aren't inside the company so that doesn't change the possible problems.  And you don't have to do the entire email 3 times.   Just use 3 different 'To:' addresses.

$mres1 = mail($mailto1, $subj, $body, $header);
$mres2 = mail($mailto2, $subj, $body, $header);
$mres3 = mail($mailto3, $subj, $body, $header);

Open in new window

LVL 111

Expert Comment

by:Ray Paseur
ID: 39574480
LVL 62

Expert Comment

by:Julian Hansen
ID: 39574501
Any particular reason you are using an HTML mime type in your message header?

You don't seem to be using any HTML markup - sending the mail as text might also have an effect (in addition to the other avice above).

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question