post to Mysql.. email too

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

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: [chris] post to Mysql.. email too

By s2smedia - August 24, 2010

no error now... but no email being sent either.. heres my code:


<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'login/lib/viewer_functions.php';
$dirsToCheck = array('XXXXX');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records
list($accountsRecords, $accountsMetaData) = getRecords(array(
'tableName' => 'accounts',
'limit' => '1',
));
$accountsRecord = @$accountsRecords[0]; // get first record

// show error message if no matching record is found
if (!$accountsRecord) {
header("HTTP/1.0 404 Not Found");
print "Record not found!";
exit;
}

?>

<?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;


}


}
$to="$accountsRecord['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");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Club Ambassadors Application</title>
<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a.indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a;}}
}
//-->
</script>
<style type="text/css">
<!--
body {

padding: 0px;
margin-top: 20px;
margin-right: 20px;
margin-bottom: 20px;
margin-left: 20px;

}
-->
</style>
</head>

<body onload="MM_preloadImages('images/splash2_r1_c1.jpg')"><form action="" method="post">
<table width="500" border="0" cellpadding="0" cellspacing="0" style="color:#333; font-family:Arial, Helvetica, sans-serif; font-size:12px; ">
<tr>
<td colspan="4" align="left" valign="top"><img src="images/applynow.gif" width="164" height="23" alt="Apply Now" /></td>
</tr>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px">Please fill out the application below. Be sure to fill out all fields in order to have your application reviewed by your club administrator.</td>
</tr>

<input type="hidden" name="submit" value="1" />
<?php if (@$errorsAndAlerts): ?>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px"><div style="color:#72528D; font-weight: bold; font-size: 15px; font-family:Arial, Helvetica, sans-serif"><br/>
<?php echo $errorsAndAlerts; ?><br/><br/>
</div></td>
</tr>
<?php endif ?>
<tr>
<td align="left" valign="top">
<input name="status" type="hidden" id="status" size="30" value="Not-Accepted"/>
<input name="club" type="hidden" id="club" size="30" value="<?php echo $accountsRecord['club_name'] ?>"/>



First Name:<br />
<input name="first_name" type="text" id="firstname" size="30" value="<?php echo htmlspecialchars(@$_REQUEST['first_name']) ?>"/>


</td>
<td align="left" valign="top">
Last Name:<br /> <input name="last_name" type="text" id="lastname" size="30" value="<?php echo htmlspecialchars(@$_REQUEST['last_name']) ?>"/>
</td>
<td align="left" valign="top">
MI:<br /><input name="middle_initial" type="text" id="middleinitial" size="5" value="<?php echo htmlspecialchars(@$_REQUEST['middle_initial']) ?>"/>

<br /></td>

</tr>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px"><div style="float:left; margin:0px 8px 0px 0px">Street Address:<br /><input name="street_address" type="text" id="streetaddress" size="30" value="<?php echo htmlspecialchars(@$_REQUEST['street_address']) ?>"/></div>
<div>City:<br /><input name="city" type="text" id="city" size="30" value="<?php echo htmlspecialchars(@$_REQUEST['city']) ?>"/></div>

<br />
<select name="state" id="dropdown">
<option value="Select State" selected="selected">Select State</option>
<option value="AL">Alabama
<option value="AK">Alaska
<option value="AZ">Arizona
<option value="AR">Arkansas
<option value="CA">California
<option value="CO">Colorado
<option value="CT">Connecticut
<option value="DE">Delaware
<option value="FL">Florida
<option value="GA">Georgia
<option value="HI">Hawaii
<option value="ID">Idaho
<option value="IL">Illinois
<option value="IN">Indiana
<option value="IA">Iowa
<option value="KS">Kansas
<option value="KY">Kentucky
<option value="LA">Louisiana
<option value="ME">Maine
<option value="MD">Maryland
<option value="MA">Massachusetts
<option value="MI">Michigan
<option value="MN">Minnesota
<option value="MS">Mississippi
<option value="MO">Missouri
<option value="MT">Montana
<option value="NE">Nebraska
<option value="NV">Nevada
<option value="NH">New Hampshire
<option value="NJ">New Jersey
<option value="NM">New Mexico
<option value="NY">New York
<option value="NC">North Carolina
<option value="ND">North Dakota
<option value="OH">Ohio
<option value="OK">Oklahoma
<option value="OR">Oregon
<option value="PA">Pennsylvania
<option value="RI">Rhode Island
<option value="SC">South Carolina
<option value="SD">South Dakota
<option value="TN">Tennessee
<option value="TX">Texas
<option value="UT">Utah
<option value="VT">Vermont
<option value="VA">Virginia
<option value="WA">Washington
<option value="DC">Washington D.C.
<option value="WV">West Virginia
<option value="WI">Wisconsin
<option value="WY">Wyoming
</select>
&nbsp;&nbsp;&nbsp;
Zip Code: <input name="zip_code" type="text" id="zipcode" size="10" value="<?php echo htmlspecialchars(@$_REQUEST['zip_code']) ?>"/></td>
</tr>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px">Birth Date:<br /><input name="birth_date" type="text" id="birthdate" size="30" value="<?php echo htmlspecialchars(@$_REQUEST['birth_date']) ?>"/>
<select name="gender" id="dropdown">
<option selected="selected">Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select></td>
</tr>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px">Player Email:<br /><input name="player_email_address" type="text" id="playeremailaddress" size="40" value="<?php echo htmlspecialchars(@$_REQUEST['player_email_address']) ?>"/></td>
</tr>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px">Parent/Guardian Name<br /><input name="parent_guardian_name" type="text" id="parentguardianname" size="40" value="<?php echo htmlspecialchars(@$_REQUEST['parent_guardian_name']) ?>"/></td>
</tr>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px">Parent Email:<br /><input name="parent_email" type="text" id="parentemail" size="40" value="<?php echo htmlspecialchars(@$_REQUEST['parent_email']) ?>"/></td>
</tr>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px">Home Phone:
<input name="home_phone" type="text" id="homephone" size="20" value="<?php echo htmlspecialchars(@$_REQUEST['home_phone']) ?>"/>
<br />
<br />
Mobile Phone:
<input name="mobile_phone" type="text" id="mobilephone" size="20" value="<?php echo htmlspecialchars(@$_REQUEST['home_phone']) ?>"/>
<br />
<br />
Other Phone:
<input name="other_phone" type="text" id="otherphone" size="20" value="<?php echo htmlspecialchars(@$_REQUEST['home_phone']) ?>"/></td>
</tr>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px"><div style="float:left; margin:0px 8px 0px 0px">School: <br /><input name="school" type="text" id="school" size="40" value="<?php echo htmlspecialchars(@$_REQUEST['school']) ?>"/></div>
<div>Grade: <br /> <input name="grade" type="text" id="grade" size="8" value="<?php echo htmlspecialchars(@$_REQUEST['grade']) ?>"/></div></td>
</tr>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px">What team are you trying out for?
<select name="team" id="dropdown">
<option value="Select One" selected="selected">Select One</option>
<option value="U12 Boys">U12 Boys</option>
<option value="U12 Girls">U12 Girls</option>
<option value="U13 Boys">U13 Boys</option>
<option value="U13 Girls">U13 Girls</option>
<option value="U14 Boys">U14 Boys</option>
<option value="U14 Girls">U14 Girls</option>
<option value="U15 Boys">U15 Boys</option>
<option value="U15 Girls">U15 Girls</option>
<option value="U16 Boys">U16 Boys</option>
<option value="U16 Girls">U16 Girls</option>
<option value="U17 Boys">U17 Boys</option>
<option value="U17 Girls">U17 Girls</option>
<option value="U18 Boys">U18 Boys</option>
<option value="U18 Girls">U18 Girls</option>
</select></td>
</tr>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px">Have you joined Club Ambassadors Facebook or Twitter yet?
<select name="facebook_twitter" id="dropdown">
<option value="Select One">Select One</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select></td>
</tr>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px">What part of this program MOST interests you?<br />
<select name="program_interest" id="dropdown">
<option value="Select One" selected="selected">Select One</option>
<option value="International Soccer Competition">International Soccer Competition</option>
<option value="Cultural Exchanges with Foreign Players ">Cultural Exchanges with Foreign Players </option>
<option value="Sightseeing and Touring another Country ">Sightseeing and Touring another Country </option>
<option value="Social relationships that will last a lifetime ">Social relationships that will last a lifetime </option>
<option value="Attending Live Professional Matches ">Attending Live Professional Matches </option>
</select></td>
</tr>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px">Why?<br />
<label>
<textarea name="why" id="why" cols="60" rows="5"><?php echo htmlspecialchars(@$_REQUEST['why']) ?>
</textarea>
</label></td>
</tr>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px">What is the furthest distance you have traveled and where did you go?
<textarea name="furthest_distance" id="furthestdistance" cols="60" rows="5"><?php echo htmlspecialchars(@$_REQUEST['furthest_distance']) ?></textarea> <br /></td>
</tr>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px">Name 3 Extracurricular activities or NON-Soccer things you do:<br />
<textarea name="3_activities" id="3activities" cols="60" rows="5"><?php echo htmlspecialchars(@$_REQUEST['3_activities']) ?></textarea></td>
</tr>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px">List up to 3 awards you have earned through school or other organizations outside of soccer.<br />
<textarea name="3_awards" id="3awards" cols="60" rows="5"><?php echo htmlspecialchars(@$_REQUEST['3_awards']) ?></textarea></td>
</tr>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px">If you had to pick one word as a player to describe you what would it be and why?

<br />
<textarea name="one_word" id="oneword" cols="60" rows="5"><?php echo htmlspecialchars(@$_REQUEST['one_word']) ?></textarea></td>
</tr>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px">If selected, what are you most hoping to gain from this experience?<br />
<textarea name="if_selected" id="ifselected" cols="60" rows="5"><?php echo htmlspecialchars(@$_REQUEST['if_selected']) ?></textarea></td>
</tr>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px">Essay Question
<p>If you were a coach selecting European players to participate in a tournament in the United States, what are 3 character traits you would look for and why? (150 words or less).<br />
<textarea name="essay_question" id="essayquestion" cols="60" rows="10"><?php echo htmlspecialchars(@$_REQUEST['essay_question']) ?></textarea>
</p>
<br /></td>
</tr>
<tr>
<td colspan="4" align="left" valign="top" style="padding:10px 0px 10px 0px"><label>
<input type="submit" name="add" id="button" value="Submit Application" />
</label></td>
</tr>
</table>
</form>
</body>
</html>

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