PHP Developers Network

Swift Mailer tutorial
Page 3 of 3

Author:  feyd [ Wed Mar 28, 2007 8:43 am ]
Post subject: 

At some point $_POST['marketsource'] was converted to a string directly from an array, thus resulting in the string "Array." Trace the variable backward to find the culprit.

Author:  Chris Corbyn [ Wed Mar 28, 2007 9:37 am ]
Post subject: 

What feyd said ;) You're overwriting $_POST["marketsource"] somewhere.

Author:  JeffBell [ Wed Mar 28, 2007 12:00 pm ]
Post subject: 

Thank you both for the response. I scoured the code and simply do not see where it could be.

In the first 50 lines, it only appears once as seen below. (In fact, it only appears once in the entire script until the HTML dump/email body creation.)

Syntax: [ Download ] [ Hide ]

/** 1 **/


/** 2 **/

//See if evil magic_quotes is enabled, and fix problems if it is

$quotes_on = (get_magic_quotes_gpc() || get_magic_quotes_runtime());

if ($quotes_on)


    foreach ($_POST as $key => $value)


        $_POST[$key] = stripslashes($value);



/** 3 **/

$_SESSION["post"] = $_POST;

/** 4 **/

//Load in the required Swift files

require_once "classes/Swift.php";

require_once "classes/Swift/Connection/SMTP.php";

/** 5 **/

//Create an empty array where we can catch any fields which were not filled in

$fields_not_set = array();


//Check if all POST data was sent, redirect with an error if not

if (empty($_POST["Name"])) $fields_not_set[] = "Name";

if (empty($_POST["Email"])) $fields_not_set[] = "Email";

//if (empty($_POST["subject"])) $fields_not_set[] = "subject";

//if (empty($_POST["comments"])) $fields_not_set[] = "comments";

//If $fields_not_set contains any values, then something wasn't filled in. Time to redirect.

if (!empty($fields_not_set))


    //Read further down to see how we'll modify form.php to handle the error

    header("Location: contact_us.php?error=incomplete&fields=" . implode(",", $fields_not_set));



//Copy the POST data to standard globals

$name = $_POST["Name"];

$email = $_POST["Email"];

$address = $_POST["Addy"];

$citystatezip = $_POST["CSZ"];

$entitytype = $_POST["entitytype"];


$marketsource = implode(", ", $_POST['marketsource']);

If there is a conflict here, perhaps you can show me the error of my ways? Or, if not, perhaps you can point me elsewhere to look? Either way I appreciate the help learning.

Author:  Chris Corbyn [ Wed Mar 28, 2007 12:41 pm ]
Post subject: 

I'll give a hint:

Syntax: [ Download ] [ Hide ]
if ($quotes_on)


    foreach ($_POST as $key => $value)


        $_POST[$key] = stripslashes($value);



What's $_POST["marketsource"]? An array. What happens when you pass that array to stripslashes() ? ;)

Author:  JeffBell [ Wed Mar 28, 2007 2:18 pm ]
Post subject: 

Author:  Chris Corbyn [ Wed Mar 28, 2007 3:51 pm ]
Post subject: 

Glad you got it sorted. To answer the question about why you get "Array" when passing an array to stripslashes(). stripslashes() expects a string, so by context, whatever you pass it will be turned into a string. If you turn an array into a string (this is called "casting" or "type-casting") PHP just makes the string "Array". stripslashes() was casting your array as a string (Array) then trying to take out \ from it before returning it, thus returning "Array". Because you then write that value back into $_POST["marketsource"], you replace the original array with a string.

Your solution will work well for your current version, but then what happens if you have an array inside another array. It only works up to two levels deep. I wouldn't stress over the solution but you may want to have a think about a (scalable) workaround for deeper nesting levels if you get bored ;)

Author:  BC Editor [ Sun Jul 06, 2014 1:56 pm ]
Post subject:  Re: Swift Mailer tutorial

Page 3 of 3 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group