post to Mysql.. email too

8 posts by 3 authors in: Forums > CMS Builder
Last Post: August 25, 2010   (RSS)

By s2smedia - August 24, 2010

I have htis set up to post to my dtabase... but I need to figure out how to also have it send to me as an email...


CODE:

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
require_once "../login/lib/init.php";

// submit form
if (@$_REQUEST['submit']) {

// error checking
$errorsAndAlerts = "";
if (!@$_REQUEST['first_name']) { $errorsAndAlerts .= "Please specify First Name!<br/>\n"; }
if (!@$_REQUEST['last_name']) { $errorsAndAlerts .= "Please specify Last Name!<br/>\n"; }
if (!@$_REQUEST['player_email_address']) { $errorsAndAlerts .= "Please specify Email Address!<br/>\n"; }
if (!@$_REQUEST['birth_date']) { $errorsAndAlerts .= "Please specify Birth Date!<br/>\n"; }
if (!@$_REQUEST['zip_code']) { $errorsAndAlerts .= "Please specify Zip Code!<br/>\n"; }
if (!@$_REQUEST['state']) { $errorsAndAlerts .= "Please specify State!<br/>\n"; }
if (!@$_REQUEST['city']) { $errorsAndAlerts .= "Please specify City!<br/>\n"; }
if (!@$_REQUEST['parent_guardian_name']) { $errorsAndAlerts .= "Please specify Parent! / Guardian<br/>\n"; }
if (!@$_REQUEST['parent_email']) { $errorsAndAlerts .= "Please specify Parent Email!<br/>\n"; }
if (!@$_REQUEST['home_phone']) { $errorsAndAlerts .= "Please specify home Phone!<br/>\n"; }
if (!@$_REQUEST['essay_question']) { $errorsAndAlerts .= "Please Complete the Essay Question!<br/>\n"; }
if (!@$_REQUEST['gender']) { $errorsAndAlerts .= "Please specify Gender!<br/>\n"; }
if (!@$_REQUEST['team']) { $errorsAndAlerts .= "Please specify Team!<br/>\n"; }


// turn off strict mysql error checking for: STRICT_ALL_TABLES
mysqlStrictMode(false); // disable Mysql strict errors for when a field isn't defined below (can be caused when fields are added later)

// add record
if (!@$errorsAndAlerts) {
mysql_query("INSERT INTO `{$TABLE_PREFIX}players` SET
status = '".mysql_real_escape_string( $_REQUEST['status'] )."',
club = '".mysql_real_escape_string( $_REQUEST['club'] )."',
first_name = '".mysql_real_escape_string( $_REQUEST['first_name'] )."',
last_name = '".mysql_real_escape_string( $_REQUEST['last_name'] )."',
middle_initial = '".mysql_real_escape_string( $_REQUEST['middle_initial'] )."',
birth_date = '".mysql_real_escape_string( $_REQUEST['birth_date'] )."',
gender = '".mysql_real_escape_string( $_REQUEST['gender'] )."',
school = '".mysql_real_escape_string( $_REQUEST['school'] )."',
grade = '".mysql_real_escape_string( $_REQUEST['grade'] )."',
street_address = '".mysql_real_escape_string( $_REQUEST['street_address'] )."',
city = '".mysql_real_escape_string( $_REQUEST['city'] )."',
zip_code = '".mysql_real_escape_string( $_REQUEST['zip_code'] )."',
state = '".mysql_real_escape_string( $_REQUEST['state'] )."',
player_email_address = '".mysql_real_escape_string( $_REQUEST['player_email_address'] )."',
team = '".mysql_real_escape_string( $_REQUEST['team'] )."',
facebook_twitter = '".mysql_real_escape_string( $_REQUEST['facebook_twitter'] )."',
parent_guardian_name = '".mysql_real_escape_string( $_REQUEST['parent_guardian_name'] )."',
parent_email = '".mysql_real_escape_string( $_REQUEST['parent_email'] )."',
home_phone = '".mysql_real_escape_string( $_REQUEST['home_phone'] )."',
mobile_phone = '".mysql_real_escape_string( $_REQUEST['mobile_phone'] )."',
other_phone = '".mysql_real_escape_string( $_REQUEST['other_phone'] )."',
program_interest = '".mysql_real_escape_string( $_REQUEST['program_interest'] )."',
why = '".mysql_real_escape_string( $_REQUEST['why'] )."',
furthest_distance = '".mysql_real_escape_string( $_REQUEST['furthest_distance'] )."',
3_activities = '".mysql_real_escape_string( $_REQUEST['3_activities'] )."',
3_awards = '".mysql_real_escape_string( $_REQUEST['3_awards'] )."',
one_word = '".mysql_real_escape_string( $_REQUEST['one_word'] )."',
if_selected = '".mysql_real_escape_string( $_REQUEST['if_selected'] )."',
essay_question = '".mysql_real_escape_string( $_REQUEST['essay_question'] )."',


createdDate = NOW(),
updatedDate = NOW(),
createdByUserNum = '".mysql_real_escape_string( $_REQUEST['num'] )."',
updatedByUserNum = '0'")
or die("MySQL Error Creating Record:<br/>\n". htmlspecialchars(mysql_error()) . "\n");
$recordNum = mysql_insert_id();

// display thanks message and clear form

// redirect to thank you page
header('Location: apply_confirm.php');
exit;
}

}

?>

Re: [s2smedia] post to Mysql.. email too

By Jason - August 24, 2010

Hi,

Yes, you can send an email from this page after you've entered the data in the database.

If you can give me some more information about the email you want to send (to, from, subject,message) I can give you an example of how to do this.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] post to Mysql.. email too

By s2smedia - August 24, 2010

I would like it to send to <?php echo $accountsRecord['email_address'] ?>

this way it sends an email to whatever email address was entered in for that account

subject Line: New Application

Message would be all of the data inputed into the form..

From: info@clubambassadors.org

Re: [s2smedia] post to Mysql.. email too

By Jason - August 24, 2010

Hi,

Try this example:

$to=$_REQUEST['player_email_address'];
$from="FROM:info@clubambassadors.org";
$subject="New Application";

$message=<<<__TEXT__

status:{$_REQUEST['status']}
club:{$_REQUEST['club']}
first_name:{$_REQUEST['first_name']}
last_name:{$_REQUEST['last_name']}
middle_initial:{$_REQUEST['middle_initial']}
birth_date:{$_REQUEST['birth_date']}
gender:{$_REQUEST['gender']}
school:{$_REQUEST['school']}
grade:{$_REQUEST['grade']}
street_address:{$_REQUEST['street_address']}
city:{$_REQUEST['city']}
zip_code:{$_REQUEST['zip_code']}
state:{$_REQUEST['state']}
player_email_address:{$_REQUEST['player_email_address']}
team:{$_REQUEST['team']}
facebook_twitter:{$_REQUEST['facebook_twitter']}
parent_guardian_name:{$_REQUEST['parent_guardian_name']}
parent_email:{$_REQUEST['parent_email']}
home_phone:{$_REQUEST['home_phone']}
mobile_phone:{$_REQUEST['mobile_phone']}
other_phone:{$_REQUEST['other_phone']}
program_interest:{$_REQUEST['program_interest']}
why:{$_REQUEST['why']}
furthest_distance:{$_REQUEST['furthest_distance']}
3_activities:{$_REQUEST['3_activities']}
3_awards:{$_REQUEST['3_awards']}
one_word:{$_REQUEST['one_word']}
if_selected:{$_REQUEST['if_selected']}
essay_question:{$_REQUEST['essay_question']}

__TEXT__;

mail($to,$subject,$message,$from) or die("Mail Error: $php_errormsg");


This will send an email to the address entered in player_email_address.
NOTE: The line "__TEXT__;" must be flush against the left side of the page. If there's a space, it will cause an error.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] post to Mysql.. email too

By s2smedia - August 24, 2010

I get this error:

Parse error: syntax error, unexpected T_SL in /home/apexsocc/club_ambassador/pages/intro/apply.php on line 82


also I dont want it to be sent to ['player_email_address']


I need it sent to $accountsRecord['email_address']

if you can just cehck this link and see how it works...

http://clubambassadors.org/pages/intro/index.php?club_name=CASL

the ?club_name=CASL makes it so it displays the CASL account records...

so when they click on Apply Now and fill out the application, it will be sent to the email_address that was set in for the CASL account... not the email address the person is entering when applying.

just a example... i have this in the form code:
<input name="club" type="hidden" id="club" size="30" value="<?php echo $accountsRecord['club_name'] ?>"/>

so now when that person applies... it can tell what INTRO Page they applied from "<?php echo $accountsRecord['club_name'] ?>"

so when they submit application.. it needs to be emailed to
<?php echo $accountsRecord['email_address'] ?>

Re: [s2smedia] post to Mysql.. email too

By Chris - August 24, 2010 - edited: August 24, 2010

Hi s2smedia,

Parse error: syntax error, unexpected T_SL


Check to make sure there are no spaces at the end of this line:

$message=<<<__TEXT__

Often, when copying-and-pasting code off the forums, somehow a space gets added to the end of each line. Unfortunately, PHP really doesn't like spaces on the ends of <<<HEREDOCs.

I need it sent to $accountsRecord['email_address']


Okay, then change the $to line to:

$to=$accountsRecord['email_address'];

You'll need to have code at the top of the page to load $accountsRecord based on the hidden form field @$_REQUEST['club'] that you're supplying.

I hope this helps. Please let me know if you have any questions.
All the best,
Chris

Re: [s2smedia] post to Mysql.. email too

By Chris - August 25, 2010

Hi s2smedia,

You're going to want to move that mail-sending block of code up above your redirect/exit code, otherwise it won't run.

Move it above "// display thanks message and clear form". That should do the trick.

Does that help?
All the best,
Chris