0

I am trying to write a basic PHP Mail Function and it doesn't work when I try using Associated/Multi-Dimensional Array stored data "$emailer['pk']['cr']" for the Message value. No error message is sent/logged and the email fails to send. Switching the Message to a standard variable allows the email to process successfully.

How can i use the Associated Array data with the Mail function, is this not allowed or am i missing something?

/* I've Removed Header Data for Safety */

// Fails
$emailer['pk']['cr'] = "=====";
$emailer['pk']['cr'] .= "The message";
$emailer['pk']['cr'] .= "=====";

mail($to, $subject, $emailer['pk']['cr'], $headers);

// Works
$message = "An example message";    

mail($to, $subject, $message, $headers);
  • And have you tried `$message = "=====The message=====";`? – Patrick Q Feb 27 '18 at 20:42
  • Hi @PatrickQ yes that works fine – James Parry Feb 27 '18 at 20:44
  • And what about `$message = $emailer['pk']['cr'];`? (and then using `$message` in the `mail()` call) – Patrick Q Feb 27 '18 at 20:56
  • That has the same problem @PatrickQ, it should be working shouldn't it? – James Parry Feb 27 '18 at 21:04
  • Make sure you have your error reporting turned on ([see here](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display)). I'm going to guess that there's something going on in code that you're not showing us. – Patrick Q Feb 27 '18 at 21:06
  • Can I ask why you want to use multidimensional array to send simple text? Are you joining variables from something else? Show me everything and I can help. Also @James Parry makes a good point. Do what he said. – technology101010 Feb 27 '18 at 21:06
  • Error reporting is on and if it should work as intended i'll have to review the source code. Thank you @technology101010 for your offer, but there's lots of includes etc and wasn't written by myself. I'll have a go at making some test scripts and see if those shed any light. The main reason for the MD Array is for sorting and storing easily (lots of data going on and was easier to pass to sessions / database etc). The emails themselves are simple notification emails to various parties. – James Parry Feb 27 '18 at 21:39

0 Answers0