Swift-Mailer error, "Mailbox address [] does not match RFC"

I created a simple PHP contact form that should send mail through the Swift-Mailer script.

The problem is that I keep getting this error

Unswitched exception 'Swift_RfcComplianceException' with message 'Mailbox address [] does not match RFC 2822, 3.6.2.

I think I am using the wrong email address. But since I use myaddress@gmail.com to check the script, the problem is probably elsewhere. This is my configuration:

If the letter is sent to:

$my_mail = ' mymail@mydomain.com '; $my_name = 'My Name'; 

Message Content:

 $name = trim($_POST['name']); $email = trim($_POST['email']); $message = trim($_POST['message']); $date = date('d/m/YH:i:s'); $ipaddress = $_SERVER['REMOTE_ADDR']; $content = $message.'\n\nSent on: '.$date.' From: '.$ipaddress; 

The function I use to send mail using swiftmailer:

 function send_mail () { require('/path/to/swift_required.php'); //The means of transport $transport = Swift_SmtpTransport::newInstance('mail.mydomain.com', 25); $transport->setUsername('myusername'); $transport->setPassword('mypass'); $mailer = Swift_Mailer::newInstance($transport); //The message $mail = Swift_Message::newInstance(); $mail->setSubject('Hello'); $mail->setFrom(array($email => $name )); $mail->setTo(array($my_mail => $my_name)); $mail->setBody($content, 'text/plain'); //Sending the message $test = $mailer->send($mail); if ($test) { echo '<p>Thank you for contacting us '.$name.'! We will get in touch soon.</p>'; } else { echo '<p>Something went wrong. Please try again later.</p>'; } } 

As you can see, this is a really simple form with three fields, name, mail and message. I also have another check configured for each of the fields on the contact form, but I think this is a little worrying here.

Thanks for the help.

Edit: Just check with gmail as an smtp server. Unfortunately, it still gives accurate results.

+6
source share
1 answer

All your data variables (addresses, names ...) seem global. Global variables cannot be read from functions unless you pass them as parameters (the recommended path) or use the global (or the $GLOBALS array).

+2
source

Source: https://habr.com/ru/post/891564/


All Articles