0

I hope someone can help.

I recently experience an issue with my php mailer code where it just stopped sending. I ran some trouble shooting and found the issue to be that whenever our domain was in the email body it wouldn't send however if I put a different domain in there then it would send.

Below is the code I am using but if I change the message body link to https://www.megacamps.net then the email doesn't send. I am at a whits end with this as the hosting company are saying its the code yet this is the test code they put on to test the mail function was working.

<?php
$to = "xxxx@xxxxxxxxxxx.co.uk";
$subject = "Test mail test";
$message = "Hello! This is a simple email message from <a href='https://www.megacamps.net'>hello</a> s2.";
$from = "xxxxxx@megacamps.net";
$headers = "From: Test" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
echo "<br>";
print date("m/d/y G.i:s<br>", time());
print "Today is ";
print date("j of F Y, \a\\t g.i a", time());
?>

If I change the href to https://www.mmmegacamps.net or any other domain it works??

Any suggestions to what i can return to my hosting company with so it can be fixed?

  • 2
    wouldn't send, or wouldn't be received? These two are not the same thing, a lot can go wrong in between those two events. Your code doesn't check whether `mail()` returns true or false so you don't actually know if the mailserver is accepting the message for sending or not each time. (I am wondering if, perhaps, somewhere one of the mails gets rejected as spam due to the content - maybe that domain is blacklisted somewhere or something. Hard to be sure, but it's a possible explanation. However first you need to verify if mail() in fact succeeds or not.) – ADyson Jul 01 '20 at 21:42
  • P.S. Here's a good general guide to debugging email problems in PHP: https://stackoverflow.com/a/24644450/5947043 – ADyson Jul 01 '20 at 21:47
  • Looks like the wrong headers to me. Should be something like: `$headers = ['From'=>$mailTitle.' <'.$fromAddress.'>', 'Content-Type'=>'text/html; charset=UTF-8'];`. The array style auto formats the correct line endings for your Server too. – StackSlave Jul 01 '20 at 21:54
  • I've put errors on and if I create an error then it shows but with the code above no errors are reported. I have also put mail sent code on the above snippet and it is showing as successfully sent. I've checked for blacklisting and the site isn't reported as being so. I would imaging if that was the case then it would affect the email address we are sending the form from however that's not the case as if I change the url the email is received. – ClickyClicks Jul 01 '20 at 22:28
  • I'm not talking about exceptions. I'm talking about the return value from mail. e.g. `$result = mail($to,$subject,$message,$headers); var_dump($result);` should give you true or false (as per the documentation). – ADyson Jul 01 '20 at 22:46
  • @ADyson, I receive the following when adding that code --> bool(true) – ClickyClicks Jul 01 '20 at 22:52
  • ok so that indicates that the message was accepted by the mailserver successfully. So if all you're changing between your failed and successful message is literally just that domain name in the link, then it likely indicates that a mail filtering system somewhere is not happy with it. I assume you've checked whether the mail ends up in the spam / junk folder or not? The mail hosting company may also be able to tell you if they were able to send the mail on to its next destination or not, and whether they got any kind of bounce / rejection message back for it. – ADyson Jul 01 '20 at 23:13
  • 1
    @ADyson Ok great, I will speak with them tomorrow. It's really strange as it means we can't even put images into the emails unless they are hosted on another domain. Once I find out what it is I will comment on here to hopefully help anyone else who expereinces similar. – ClickyClicks Jul 01 '20 at 23:23

0 Answers0