include_once 'PATH/TO/swift_required.php';

//put info into an array to send to the function
$info = array(
    'username' => $username,
    'email' => $email,
    'key' => $key
);

//send the email
if(send_email($info)){

    //email sent
    $action['result'] = 'success';
    array_push($text,'Thanks for signing up. Please check your email for confirmation!');

}else{

    $action['result'] = 'error';
    array_push($text,'Could not send confirm email');

}

I am using the above code and it is giving me this error.Please help

Fatal error: Uncaught exception 'Swift_RfcComplianceException' with message 'Address in mailbox given [] does not comply with RFC 2822, 3.6.2.' in /path/to/MailboxHeader.php:319 Stack trace: #0 /path/to/MailboxHeader.php(249): Swift_Mime_Headers_MailboxHeader->_assertValidAddress('') #1 /path/t/MailboxHeader.php(107): Swift_Mime_Headers_MailboxHeader->normalizeMailboxes(Array) #2 /path/t/MailboxHeader.php(71): Swift_Mime_Headers_MailboxHeader->setNameAddresses(Array) #3 /path/t/SimpleHeaderFactory.php(74): Swift_Mime_Headers_MailboxHeader->setFieldBodyModel(Array) #4 /path/t/SimpleHeaderSet.php(87): Swift_Mime_SimpleHeaderFactory->createMailboxH in /path/t/MailboxHeader.php on line 319

It seems send_mail() function is receiving a malformed email address, check the submitted array $info to see what is wrong. By the way, Swiftmailer requires at least four parameters in order to work: setTo(), setFrom(), setSubject() and setBody(). Check documentation for more information: http://swiftmailer.org/docs/sending.html

I have soloved the above problem myself but now i am facing another problem.It says coloumn and value count does not matach.Here is the error message
User could not be added to the database. Reason: Column count doesn't match value count at row 1
and this is my code i have written code correctly there is no difference in values and coloumns but it still show the error.I think the problem is somewhere else .

include_once 'inc/php/config.php';
include_once 'inc/php/functions.php';
//check if the form has been submitted
if(isset($_POST['signup'])){
$action = array();
$action['result'] = null;

$text = array();
    $username = mysql_real_escape_string($_POST['username']);
    $password = mysql_real_escape_string($_POST['password']);
    $email = mysql_real_escape_string($_POST['email']);
    $name =  mysql_real_escape_string($_POST['name']);
    $parentage = mysql_real_escape_string($_POST['parentage']);
    $residence = mysql_real_escape_string($_POST['residence']);
    $tehsil = mysql_real_escape_string($_POST['tehsil']);
    $district = mysql_real_escape_string($_POST['district']);
    $occupation = mysql_real_escape_string($_POST['occupation']);
    $whwo = mysql_real_escape_string($_POST['whwo']);
    $nationality = mysql_real_escape_string($_POST['nationality']);
    $contactno  = mysql_real_escape_string($_POST['contactno']);
    $bloodgroup = mysql_real_escape_string($_POST['bloodgroup']);
    $identificationmark = mysql_real_escape_string($_POST['identificationmark']);
    $policestation = mysql_real_escape_string($_POST['policestation']);


//setup some variables/arrays
//$action = array();
//$action['result'] = null;

//$text = array();

//check if the form has been submitted
if(isset($_POST['signup'])){

    //cleanup the variables
    //prevent mysql injection
    $username = mysql_real_escape_string($_POST['username']);
    if(empty($username)){ $action['result'] = 'error'; array_push($text,'You forgot your username'); }
    $password = mysql_real_escape_string($_POST['password']);
    if(empty($password)){ $action['result'] = 'error'; array_push($text,'You forgot your password'); }
    $email = mysql_real_escape_string($_POST['email']);
    if(empty($email)){ $action['result'] = 'error'; array_push($text,'You forgot your email'); }

    //quick/simple validation
            if($action['result'] != 'error'){
        //no errors, continue signup
           $password = md5($password);

    //get the new user id
 //   $userid = mysql_insert_id();

    //create a random key
   // $key = $username . $email . date('mY');
    //$key = md5($key);



    //add confirm row
    //$confirm = mysql_query("INSERT INTO `confirm` VALUES($userid'$username','$key','$email','$name','$parentage','$residence','$tehsil','$district','$occupation','$whwo','$nationality','$contactno','$bloodgroup','$identificationmark','$policestation')");

    //if($confirm){
      //      echo "hello";
        //let's send the email

    //}else{

      //  $action['result'] = 'error';
       // array_push($text,'Confirm row was not added to the database. Reason: ' . mysql_error());

    }
    }

  //  $action['text'] = $text;




//  if($action['result'] != 'error'){

//      $password = md5($password);

        //add to the database
        $add = mysql_query("INSERT INTO `users` VALUES(NULL,'$username','$password','$email','$name','$parentage','$residence','$tehsil','$district','$occupation','$whwo','$nationality','$contactno','$bloodgroup','$identificationmark','$policestation',0)");

        if($add){

            //get the new user id
            $userid = mysql_insert_id();

            //create a random key
            $key = $username . $email . date('mY');
            $key = md5($key);

            //add confirm row
            $confirm = mysql_query("INSERT INTO `confirm` VALUES('$key','$username','$password','$email','$name','$parentage','$residence','$tehsil','$district','$occupation','$whwo','$nationality','$contactno','$bloodgroup','$identificationmark','$policestation')");

            if($confirm){

                //include the swift class
                include_once 'inc/php/swift/swift_required.php';

                //put info into an array to send to the function
                $info = array(
                    'username' => $username,
                    'email' => $email,
                    'key' => $key);

                //send the email
                if(send_email($info)){

                    //email sent
                    $action['result'] = 'success';
                    array_push($text,'Thanks for signing up. Please check your email for confirmation!');

                }else{

                    $action['result'] = 'error';
                    array_push($text,'Could not send confirm email');

                }

            }else{

                $action['result'] = 'error';
                array_push($text,'Confirm row was not added to the database. Reason: ' . mysql_error());

            }

        }else{

            $action['result'] = 'error';
            array_push($text,'User could not be added to the database. Reason: ' . mysql_error());

        }

    }

    $action['text'] = $text;
   ?>
//}



<?php
include 'inc/elements/header.php'; ?>

<?= show_errors($action); ?>

<form method="post" action="">

    <fieldset>

        <ul>
            <li>
                <label for="username">Username:</label>
                <input type="text" name="username" />
            </li>
            <li>
                <label for="password">Password:</label>
                <input type="password" name="password" />
            </li>
            <li>
                <label for="email">Email:</label>
                <input type="text" name="email" />
            </li>
            <li>
                    <label for ="name">Name:</label>
                        <input type="text" name="name"/>
                </li>
                <li>
                    <label for ="parentage">S/o,D/o,W/o:</label>
                        <input type="text" name="parentage"/>
                </li>
                <li>
                    <label for ="residence">Residence:</label>
                        <input type="text" name="residence"/>
                </li>
                <li>
                    <label for ="tehsil">Tehsil:</label>
                        <input type="text" name="tehsil"/>
                </li>
                <li>
                    <label for ="district">District:</label>
                        <input type="text" name="district"/>
                </li>
                <li>
                    <label for ="age">Age:</label>
                        <input type="text" name="age"/>
                </li>
                <li>
                    <label for ="occupation">Occupation:</label>
                        <input type="text" name="occupation"/>
                </li>
                <li>
                    <label for ="As in WHWO">As in WHWO:</label>
                        <input type="text" name="whwo"/>
                </li>
                <li>
                    <label for ="nationality">Nationality:</label>
                        <input type="text" name="nationality"/>
                </li>
                <li>
                    <label for ="contactno">Contact No:</label>
                        <input type="text" name="contactno"/>
                </li>
                <li>
                    <label for ="bloodgroup">Blood Group:</label>
                        <input type="text" name="bloodgroup"/>
                </li>
                <li>
                    <label for ="identificationmark">Identification Mark:</label>
                        <input type="text" name="identificationmark"/>
                </li>
                <li>
                    <label for ="policestation">Police Station:</label>
                        <input type="text" name="policestation"/>
                </li>
                <li>
                <input type="submit" value="Signup Now" class="large blue button" name="signup" />
            </li>
        </ul>

    </fieldset>

</form>

<?php
include 'inc/elements/footer.php'; ?>

The insert queries are wrong, you have to declare the fields not only the values, so this:

$add = mysql_query("INSERT INTO `users` VALUES(NULL,'$username','$password','$email','$name','$parentage','$residence','$tehsil','$district','$occupation','$whwo','$nationality','$contactno','$bloodgroup','$identificationmark','$policestation',0)");

should be something like:

$add = mysql_query("INSERT INTO `users` (id, username, password, email, name, parentage, residence, tehsil, district, occupation, whwo, nationality, contactno, bloodgroup, identificationmark, policestation, another_field) VALUES(NULL,'$username','$password','$email','$name','$parentage','$residence','$tehsil','$district','$occupation','$whwo','$nationality','$contactno','$bloodgroup','$identificationmark','$policestation',0)");

obviously mine is an example, since I don't know the names of the fields in users table.

I have already inserted the sql query for fields manually

Here is how i have inserted the sql query for fields

 CREATE TABLE `users` (
`id` int( 11 ) NOT NULL AUTO_INCREMENT ,
`username` varchar( 50 ) NOT NULL default '',
`password` varchar( 128 ) NOT NULL default '',
`email` varchar( 250 ) NOT NULL default '',
`name` varchar( 250 ) NOT NULL default '',
`parentage` varchar( 250 ) NOT NULL default '',
`residence` varchar( 250 ) NOT NULL default '',
`tehsil` varchar( 250 ) NOT NULL default '',
`district` varchar( 250 ) NOT NULL default '',
`age` varchar( 250 ) NOT NULL default '',
`occupation` varchar( 250 ) NOT NULL default '',
`whwo` varchar( 250 ) NOT NULL default '',
`nationality` varchar( 50 ) NOT NULL default '',
`contactno` varchar( 50 ) NOT NULL default '',
`bloodgroup` varchar( 11 ) NOT NULL default '',
`identificationmark` varchar( 50 ) NOT NULL default '',
`policestation` varchar( 250 ) NOT NULL default '',
`active` binary( 1 ) NOT NULL default '0',
PRIMARY KEY ( `id` )
) ENGINE = MYISAM AUTO_INCREMENT =27 DEFAULT CHARSET = utf8

I soloved this one the error was in the first code .The error was because i created database coloums manually in mysql.First three through sql query and rest of fields manually .I recreated all through sql query Thanks all for participation.I knew there is something wrong with values and fields but could not figure out where.All the code was right the only thing i did was to create some fields manually and some through sql query which seems to me the reason for error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.