0

I am using this line to concatenate variables for a mail out

$message = $message1." ".$message2." ".$message3." ".$message4." ".$message5." ".$message6." ".$message7." ".$message8." ".$message9;

This works fine, except I have another four variables to add, but when I add more than $message9 it stops the mail out.

Here is my mail loop

// Mail it

$filename = "..email_addresses.txt";
//start mail out
 set_time_limit(0); // this will keep the script from stopping if it takes longer then 30 seconds, must have this here
 $emailaddress = file($filename, FILE_IGNORE_NEW_LINES);
 $emailsubject = "New messages added to the website";
 $fromaddress = "sample@sample.com";
 $i = count($emailaddress);
 $z = 0;
 if ($i != 0)
 {
 while ($i != $z)
 {
 mail($emailaddress[$z], $emailsubject, $message, $headers); 

 ++$z;     
mark.four
  • 9
  • 4
  • 3
    What exactly does "stops the mail out" mean? Do you get a specific error or something? Please be more specific and indicate what debugging you've done so far. I'm not aware of any limitation to the number of variables you can concatenate into a single statement in PHP - and certainly your code won't hit a limit if you add a few more...demo: https://3v4l.org/PuC5Y . Maybe the actual content you're putting in there is hitting some other kind of limit, but it's all a bit unclear. Is `mail` still returning true, in that scenario? Your code doesn't seem to even try to check that! – ADyson Jul 04 '23 at 16:01
  • 1
    Can you please tidy up that code a bit? There are a lot of pointless comments cluttering it all up, making it harder to read. Over-documenting is a thing. If you use proper code indention instead (indenting if/foreach etc), you don't need silly comments like `}//end if` or `{//start else` (which is already _pretty_ obvious) – M. Eriksson Jul 04 '23 at 16:02
  • with $message1 variable to ... $message9 variable the mail out works, but if I add another variable i.e. $message10 there is no mail out result, I do not get an error message just no email arrives – mark.four Jul 04 '23 at 16:08
  • How far through the code does it get? Do you have anything in your error log? What is in the `$message.` variables? If you use an array of string variables instead of your flat ones, you could use `implode()` to concatenate them - does that make any difference? – droopsnoot Jul 04 '23 at 17:17
  • I did convert the extra lines to an array and concatenated into 1 line with the same result, then I trimmed down the lines so that there was only message8 but still the same result, then I removed 3 lines of the message which were written in Spanish and German and the email send works fine, seems like it is a language issue this is the line that I am using in my header information $headers .= "Content-type: text/html; charset=utf8mb4" . "\r\n"; – mark.four Jul 05 '23 at 18:23
  • Solved, it was the Gmail line limit, so I needed to intersperse the $message lines with $message .= "\r\n"; – mark.four Jul 06 '23 at 20:22

0 Answers0