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 9176429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:06:29+00:00 2026-06-17T17:06:29+00:00

Im not quiet sure where im going wrong but, when i use this mail

  • 0

Im not quiet sure where im going wrong but, when i use this mail function:

    <?php
function printMember($member) {
    foreach($member as $key=>$value) {
        echo "$key : $value <br />";
    }
}

$to = 'email@address.co.za';

$subject = 'Application Form';

$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "BCC: email@address.co.za\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";


$json = $_POST['parameters'];
$json_string = stripslashes($json);
$data = json_decode($json_string, true);

$depCount = count($data["dependants"]);


$msg .= "<h2>Main member data:</h2>";
$msg .= printMember($data["mainmember"]);

$msg .= "<h2>There are $depCount Dependants</h2>";

foreach ($data["dependants"] as $index => $dependant) {
   $msg .= "<h2>Dependant $index</h2>";
   $msg .= printMember($dependant);
}

 mail($to, $subject, $msg, $headers);

it returns:

Main member data:
There are 3 Dependants
Dependant 0
Dependant 1
Dependant 2

instead of (as displayed in console):

Main member data:
name : name
surname : surename
id : 6110190027087
age : 51
gender : Female
townofbirth : george
email : naem@gmail.com
contact : 0512148615
passport : 1111111111111
postal : test
postal_code : 4545
residential : test
residential_code : 4545

There are 1 Dependants
Dependant 1
name : dep1
surname : dep1
id : 8202255133088
age : 30
gender : Male
townofbirth : dep1
cell : 0145264448
email : dep1
passport : 2222222222222
relationship : parent

here’s the JSON:

{
    "mainmember": {
        "name": "name",
        "surname": "surename",
        "id": "6110190027087",
        "age": "51",
        "gender": "Female",
        "townofbirth": "george",
        "email": "naem@gmail.com",
        "contact": "0512148615",
        "passport": "1111111111111",
        "postal": "test",
        "postal_code": "4545",
        "residential": "test",
        "residential_code": "4545"
    },
    "dependants": [
        {
            "name": "dep1",
            "surname": "dep1",
            "id": "8202255133088",
            "age": "30",
            "gender": "Male",
            "townofbirth": "dep1",
            "cell": "0145264448",
            "email": "dep1",
            "passport": "2222222222222",
            "relationship": "parent"
        }
    ]
}

I did get an answer on this: Parsing Duplicatable Form's JSON data to PHP for Mail

But just not the actual mailing..

Any help greatly appreciated

  • 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-06-17T17:06:30+00:00Added an answer on June 17, 2026 at 5:06 pm

    The problem is on the printMember() function, you are doing echo and that doesn’t return anything: Update your printMember function like this:

    function printMember($member) {
        foreach($member as $key=>$value) {
            //Fill the aux string first
            $str.= "$key : $value <br />";
        }
        //string that will be added to $msg variable inside the loop
        return $str;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not quite sure where I'm going wrong with this implementation and what adjustment
I'm not quite sure what's going on, but several issues are occurring on our
I'm not quite sure how to go about styling this particular bit of php:
Not quite sure where I'm going wrong - I'm trying to train OpenCV for
I'm not sure where I've gone wrong, but I have an iphone project that
I'm sure this is going to sound very weird, but I'll ask anyway. I
I'm quite new to using php so im not sure if this is possible
This is a very basic regex question, but I'm not quite sure where I
Not quite sure how to word this question. I am wondering if there is
Im not quite sure what I am doing wrong here, I have folloed the

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.