开发者

How to incorporate php mail with dynamic input values

on my site, I have a link in my nav bar that says 'refer a friend' using jquery a box pops up with two input boxes, one that is a place to enter the persons email in which you want to send a referral email and one box to enter in their name. I am looking for a good tutorial in how to get started about dynamically adding the values that are typed in, and sending them to the php mail on this same page. I am a newbie at php and some sort of guidance would be very helpful

thanks in advance

This is what I've come up with so far:

$

referral_email = $_POST['referral_email'];
$referral_name = $_POST['referral_name'];

if(isset($_POST['referral_form']) ) {



    $query = "SELECT * FROM `cysticUsers` WHERE `id` = '" . $prof->id . "'";
    $request = mysql_query($query,$connection) or die(mysql_error());
    $result = mysql_fetch_array($request); 

    $Email = $result['Email'];

        $to = $referral_email;
        $subject = "$auth->first_name $auth->last_name sent you an invitation to CysticLife.org";
        $message = "Hello $referral_name, $auth->first_name $auth->last_name sent you an invite to join CysticLife.org ";
        $from = "$auth->Email";
        $headers  = 'MIME-Version: 1.0' . "\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
        $headers .= "From: $from";
        mail($to, $subject, $message, $headers);
    }

?>
<div id="toggle_me">
        <div id="refer_title">
            Invite a friend
            <a id="nevermind" href="#">nevermind</a>
        </div>
    <form name="refer_email" method="post" action="#">
        <table id="refer_house">
            <tr>
                <td class="refer_left">
                    To:
                </td>
                <td class="refer_right">
                <input type="text" name="to_email" value="Enter Recipient's E-Mail Address<?php $_POST[开发者_Python百科'referral_email'];?>" class="defaulted"/>
                </td>
            </tr>
            <tr>
                <td class="refer_right">
                </td>
                <td class="refer_right">
                    <input type="text" name="to_name" value="Enter Recipient's Name<?php $_POST['referral_name'];?>" class="defaulted"/>
                </td>
            </tr>
        </table>
        <div id="refer_submit">
            <input type="submit" name="referral_form" value="Send" />
        </div>


A simple form would be:

referFriend.php:

<?php

    $referralEmail = $_REQUEST['referralEmail'];
    $referralName = $_REQUEST['referralName'];

    $msgSubject = "Hey $referralName, Bob recommends you check this out!";
    $msgBody = "$referralName,

    Check this out: http://www.google.com

    Your friend,
    Bob";

    mail($referralEmail, $msgSubject, $msgBody);

?>

Assuming you are sending 'referralEmail' and 'referralName' from the jQuery script. You'll also need to plug in the referrer's name in place of 'Bob.'

Additionally you should be validating the data as well as using $_GET or $_POST (as opposed to $_REQUEST) depending on how you're sending the variables.

You could test that using:

http://www.your-domain.com/referFriend.php?referralEmail=test@test.com&referralName=Chad


If you want to do this asynchronously (without a page load) you'll have to send the contents of the input to another PHP page via AJAX. Otherwise you should be able to just use a 's build in submit and catch the contents at the top of the page.

If you're interested in doing it asynchronously you can take a look at jQuery's .ajax, .post or .get functions. Let us know if you have more questions about these functions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜