Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6087907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:55:27+00:00 2026-05-23T11:55:27+00:00

I have built a simple PHP contact form that is supposed to send mail

  • 0

I have built a simple PHP contact form that is supposed to send mail trough the Swift-Mailer script.

Problem is I keep getting this error

Uncaught exception
‘Swift_RfcComplianceException’ with
message ‘Address in mailbox given []
does not comply with RFC 2822, 3.6.2.’

Which I guess means I am using an invalid e-mail address. But since I am using myaddress@gmail.com to test the scrip the problem is probably somewhere else. This is my configuration:

Where the mail is sent to:

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

The content of the message:

$name = trim($_POST['name']);
$email = trim($_POST['email']);
$message = trim($_POST['message']);
$date = date('d/m/Y H:i:s'); 
$ipaddress = $_SERVER['REMOTE_ADDR'];  

$content = $message.'\n\nSent on: '.$date.' From: '.$ipaddress;

The function i use to send the 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 it is really simple form with three fields, name, mail and message. I also have other validation set up for each of contact form fields, but I think it is of little concern here.

Thank you for the help.

Edit:
Just test with using gmail as the smtp server. Unfortunately it still gives the same exact results.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:55:27+00:00Added an answer on May 23, 2026 at 11:55 am

    All your data variables (addresses, names…) appear to be global. Global variables cannot be read from within functions unless you pass them as parameters (the recommended way) or use the global keyword (or the $GLOBALS array).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple php site that I built, but for some reason my
Thanks in advance! I have a simple mysql and php blog that I built
I have a simple PHP form that sends an email to its visitors from
I have a simple website built using PHP. It is hosted on a Linux
I built a very simple app using a PHP form with a bit of
I have this simple script that catches all mouse clicks, unless you click on
I have a very simple chat system I've built using PHP and MySQL (this
We have a cron'ed PHP script that checks an inbox every ten minutes. The
I have built a simple site that allows users to share code where the
I have built a website using php and simple HTML/CSS for a client. In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.