0

I have the below part of code which works fine but all of a sudden it started not working (The mail is not getting delivered) from today. I had a look inthe SO regarding this and didn't find any suitable answers.

 $content = chunk_split(base64_encode($mpdf->Output($file.'.pdf', 'S')));

 $separator = md5(time());

 $eol = PHP_EOL;

 $headers = "From: ".$fromemail['Fromemail'] . $eol;
 $headers .= "Cc: ".$ccemail['Email'] . $eol;
 $headers .= "Importance: High\n"; 
 $headers .= "MIME-Version: 1.0".$eol; 
 $headers .= "Content-Type: multipart/mixed;boundary=\"" . $separator . "\"".$eol.$eol;


 // message
 $body .= "Content-Transfer-Encoding: 7bit".$eol;
 $body .= "This is a MIME encoded message.".$eol;
 $body = "--" . $separator.$eol;
 $body .= "Content-Type: text/html; charset=\"UTF-8\"".$eol;
 $body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
 $body .= $message.$eol;

 // attachment
 $body .= "--" . $separator.$eol;
 $body .= "Content-Type: application/octet-stream; name=\"" . $filename . '.pdf' . "\"".$eol;
 $body .= "Content-Transfer-Encoding: base64".$eol;
 $body .= "Content-Disposition: attachment".$eol.$eol ;
 $body .= $content.$eol;
 $body .= "--" . $separator . "--";

 //SEND Mail
 if (mail($mailto, $subject, $body, $headers)) {
         //echo "mail send ... OK"; // or use booleans here
  } 

Please let me know where I went to a wrong direction.

John Conde
  • 217,595
  • 99
  • 455
  • 496
John
  • 565
  • 8
  • 23
  • 1
    What do you mean by "stopped working"? Does that mean you are getting an error? is the call to `mail()` returning `false`? Is the email not getting delivered? – Mr Glass Jun 15 '18 at 14:08
  • @MrGlass The mail is not getting delivered. I will update this in my question – John Jun 15 '18 at 14:09
  • Does the server send an e-mail? – Ron van der Heijden Jun 15 '18 at 14:10
  • Do you have a mail server setup? I'm assuming this is your localhost? If so you need to specify to PHP how the mails are supposed to be handled. – Sam Jun 15 '18 at 14:10
  • @Samuel I am working on a Server and not in the localhost – John Jun 15 '18 at 14:11
  • @RonvanderHeijden No, the Server is not sending the emails – John Jun 15 '18 at 14:12
  • @John so you have to look at your Mail server settings. Most servers have the options under your admin panel. Was it working before? – Sam Jun 15 '18 at 14:12
  • 1
    @John, have you tried sending an email to an address using the same domain as the `From` address? It's possible this is due to an SPF record failure (your email may be getting marked as spam). – Mr Glass Jun 15 '18 at 14:12
  • maybe do you get an error ? – Diego Avila Jun 15 '18 at 14:14
  • 1
    mail not being _delivered_ is not the same as mail not being _sent_. There are a lot of steps in between where it could go wrong. If you haven't changed anything in the code, then it seems unlikely to be directly the fault of the code, but we could do with narrowing down the problem. You first need to verify if the emails are being _sent_ by inspecting the appropriate logs in your server, checking the response from `mail()` in your code, etc. If they are being sent, then non-delivery could be network issues, spam filters, DNS etc etc etc. See https://stackoverflow.com/a/24644450/5947043 – ADyson Jun 15 '18 at 14:14
  • 3
    Aside of the e-mail server problems, I would advice the usage of a class like phpmailer or swiftmailer instead of the native php mail function. – Ron van der Heijden Jun 15 '18 at 14:16
  • 1
    why is phpmailer even tagged here? – Masivuye Cokile Jun 15 '18 at 14:16
  • @MrGlass Yeah, i tried it by sending it to my email address of the same doamin and I didn't received it – John Jun 15 '18 at 14:18
  • anything in mail queue? Run: `mailq` – webaholik Jun 15 '18 at 14:18
  • @John, does the email appear in your PHP mail.log? – Mr Glass Jun 15 '18 at 14:23

0 Answers0