Question

This is the scenario,A user select a plan from a planning page,once he selected a plan that will be shown in a table,so he wants his plan on email,so how can set email body as his selected plan page.If is there any solution please help me.

Was it helpful?

Solution

Two basic steps:

1) Submit the data that you requested using an HTML form with the POST method. We'll assume that you are keeping this data in a form field named 'plans'.

2) You can then use the mail() function in PHP. Here is an altered example from the mail() PHP Manual Page:

<?php
    //This belongs in whichever file is called by your HTML form

    $to      = 'yourtarget@example.com';
    $subject = 'Plans';

    //Retrieve the plan contents from the form's posted data
    $message = $_POST['plans_field'];

    $headers = 'From: webmaster@example.com' . "\r\n" .
        'Reply-To: webmaster@example.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();

    mail($to, $subject, $message, $headers);
?>

Edit: To get the actual table contents I would probably use some jQuery. Let's assume your table looks like this:

<table>
    <tr><td id="plan_data">Here is all of your plan data!</td></tr>
</table>

In addition, you will have a hidden field in your form (since you aren't requesting the user actually provide the data themselves, we will use a hidden field).

<form>
    <input type="hidden" id="plans_field" name="plans_field" value="" />
    <input type="submit" id="submit" />
</form>

We'll intercept the form submission (since the hidden field is current an empty string) and, using jQuery, we'll populate the hidden field's value with the table cell contents:

$(document).ready(function() {

    $("#submit").on("click", function() {

        $("#plans_field").val($("#plan_data").html());

    });

});

The line inside the on click function might look a bit lengthy, but it's basically saying: "I want to set the value of the hidden plans_field to the contents of the plan_data cell."

Please remember that these are just examples and that my answer is not foolproof: a browser with JavaScript disabled would be able to submit that form and the empty string would remain, so some error checking on your end would be a good idea.

OTHER TIPS

The best way would be using $_GET and/or $_POST methods. I suggest looking up tutorials as to how to use these. It wouldn't take too long as it sounds like a fairly simple problem you need solved.

I would add however, that this is not really an appropriate StackOverflow question. Stack-O is really for specific problems, not for getting someone else to build a whole page for you.

Have a look at this or something like CodeAcademy. They walk you through pretty much everything you need to know about PHP and it's divided into subsections quite nicely. There are places you could find specific PHP tutorials for problems similar to yours, but learning the language properly is a much better way to go.

Note: Homeandlearn use the now deprecated mysql, so I suggest looking up mysqli, or even better PDO if you will be querying databases.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top