cancel
Showing results for 
Search instead for 
Did you mean: 

php mail() on free webspace

UncleZen
Rising Star
Posts: 111
Thanks: 16
Fixes: 2
Registered: ‎15-08-2008

php mail() on free webspace

I using the free webspace i have with by broadband to develop a website.

I'm finding that mail() does not always send.

I'm doing everything right, but sometimes it just doesnt send emails, Is there a block in place?

 

7 REPLIES 7
spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: php mail() on free webspace

On the ccgi server, the PHP mail() function used directly or via the PHPmailer interface appears to be working OK for me. Also using the PHPmailer sendmail and SMTP interfaces works OK. This is for messages sent to Plusnet and Gmail addresses.

Do you get any error notification when mail() fails to send?

David
UncleZen
Rising Star
Posts: 111
Thanks: 16
Fixes: 2
Registered: ‎15-08-2008

Re: php mail() on free webspace

I've discovered that if I don't supply headers it works, but as soon as I supply a header such as "From: noreply@somewhere.com \r\n" it doesn't. Of course I need to supply a header, mail is always returning true.

On another page I have some code that sends a simple email to 1 recipient  (including headers) it's been working for weeks and today nothing no reason, just returns true like it's done it.

I've never used phpmailer or SMTP, maybe I should investigate these as an alternative

 

spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: php mail() on free webspace

My test included a From: header, but since it was the last additional header it wouldn't be terminated with "\r\n". If yours is last have you tried without those characters? Presumably the From domain actually exists?

Unfortunately mail() returning TRUE only means the message has been accepted, it doesn't mean it's deliverable. Have you included an additional 5th parameter to set a bounce address? The default is effectively a blackhole. This would be like

// Additional parameter to set Envelope From/Return-Path
$parameter = "-fmailboxname@username.plus.com";

if(!mail($emailTo, $emailSubject, $body, $headers, $parameter)) {
   echo "Message was not submitted.<br>\n";
   echo "PHP mail() function failed.";
   exit;
}
David
UncleZen
Rising Star
Posts: 111
Thanks: 16
Fixes: 2
Registered: ‎15-08-2008

Re: php mail() on free webspace

I'm using mail() exactly as shown on w3schools. The header is terminated with \r\n but as there is only 1 header, maybe that is not needed, I'll try that tonight (doing this after work). The from email address does not exist, its a NoReply@mydomain.com address.

Ive used that approach before and its worked, Its also worked successfully, but intermittently in the PN hosting recently.

I've not used the 5th parameter for a bounce address, I may give that a try.

UncleZen
Rising Star
Posts: 111
Thanks: 16
Fixes: 2
Registered: ‎15-08-2008

Re: php mail() on free webspace

OK, well, I seem to have resolved this.

if I use my plusnet email address (something@myusername.plus.com) as the From, like this:

$noReplyEmailAddress="test@myusername.plus.com";
$headers="From: ".$noReplyEmailAddress.$newline."Bcc: ".$bccEmailAddress;

Where $newline is "\r\n" and Bcc is a working email address.

It all seems to work as expected.

This doesnt explain why it did work previously, then stopped, started and stopped for good. Maybe there was a change behind the scenes.

spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: php mail() on free webspace

I've done a bit of experimentation on mail() behaviour sending to a Plusnet address.

  • sending works fine with or without CRLF at the end of additional headers.
  • sending with the From: header set to a non-Plusnet address which exists works fine. Sending a reply to that From address (from the Plusnet recipient) works.
  • sending with the From: header set to the same valid domain but with invalid local part fails and no bounce message is received at a valid bounce address.

Just wondering if spam checking is an issue here. Sending is spam checked on CCGI as is receipt at my Plusnet address.

David
spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: php mail() on free webspace


@spraxyt wrote:
  • sending with the From: header set to the same valid domain but with invalid local part fails and no bounce message is received at a valid bounce address.

In fact that email *did* eventually turn up but after being delayed by 2hr 13 min at handover from the ccgi mail relay and Plusnet avasin. The tracking headers are as follows:

Return-path: <bbbbbbbbb@yyyyyyyyy.force9.co.uk>
Envelope-to: aaaaaaaaa@yyyyyyyyy.force9.co.uk
Delivery-date: Thu, 17 Nov 2016 01:07:58 +0000
Received: from [212.159.8.109] (helo=avasin09.plus.net)
	  by inmx03.plus.net with esmtp (PlusNet MXCore v2.00) id 1c7BBG-0002V1-EG 
	  for aaaaaaaaa@yyyyyyyyy.force9.co.uk; Thu, 17 Nov 2016 01:07:58 +0000
Received: from mailrelay3c50.megamailservers.eu ([91.136.10.252])
	by avasin09.plus.net with Plusnet Cloudmark Gateway
	id 8p7w1u0025SGcrf01p7yT5; Thu, 17 Nov 2016 01:07:58 +0000
Received: from web92c50.megawebservers.eu ([10.130.1.92])
	by mailrelay3c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id uAGMshWd003357
	for <aaaaaaaaa@yyyyyyyyy.force9.co.uk>; Wed, 16 Nov 2016 22:54:43 +0000
Received: (from ccgi.yyyyyyyyy.force9.co.uk@localhost)
	by web92c50.megawebservers.eu (8.14.4/8.12.2/Submit) id uAGMsrHE017577;
	Wed, 16 Nov 2016 22:54:53 GMT
Date: Wed, 16 Nov 2016 22:54:53 GMT
Message-Id: <201611162254.uAGMsrHE017577@web92c50.megawebservers.eu>
To: aaaaaaaaa@yyyyyyyyy.force9.co.uk
MIME-Version: 1.0
Content-type: text/html; charset=iso-8859-1
From: idontexist@validdomain.co.uk
Subject: Testing use of mail() with invalid From address
David