0
votes

I keep getting a fatal error message when getting multiple emails from firebase to php (passing data from firebase to HTML then to html to PHP)

Fatal error: Uncaught exception 'Swift_RfcComplianceException' with message 'Address in mailbox given [[email protected],[email protected]] does not comply with RFC 2822, 3.6.2

I tried getting a single email from firebase and it worked perfectly, but multiple emails with any email addressed I used the same issue arise

<?php

require '/Vendor/Mail/lib/swift_required.php';

// validation expected data exists if required later
if (!isset($_POST['agent_e'])  {
    died('We are sorry, but there appears to be a problem with the form you submitted.');
}

$email_to = $_POST['agent_e']; // required
$headers .= "MIME-Version: 1.0\r\n";

$mailer   = Swift_Mailer::newInstance($transport);
$message  = Swift_Message::newInstance('')
    ->setSubject($subject)
    ->setFrom(array('[email protected]' => 'mailer'))
    ->setTo(array($email_to))
    ->setBody('<html>' .
' <body>' .
'  ' . // Embed the file
$messageBody .
'  ' .
' </body>' .
'</html>',
'text/html' // Mark the content-type as HTML
);

// Send the message
$result = $mailer->send($message);

Emails from database example :

enter image description here

Error :

enter image description here

1
What does the above code have to do with firebase? All I can see is you getting the value from $_POST['agent_e'], which you then use as to-address. Anyway, have you done a var_dump($email_to); to check what the data looks like? Also, why are you putting that variable in an array in the setTo()-method?Magnus Eriksson

1 Answers

0
votes

i solved the problem with Splitting the emails i got from firebase to an array

as below code :

$email_to = str_replace(' ','',$email_to);
$email_to = (string) $email_to;
$email_to = explode(',',$email_to);