PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm a novice to the PHP world. I'm working on a web form on my site and I can get the code to post to my database but, i can't get the form e-mailed to me when a client fills it out and submits it. Here's the code
<?php
ini_set ('display_errors', 1); //Display all errors.
error_reporting (E_ALL & ~ E_NOTICED); //Don't show notices.
// This page receives data from contact_info.htm.
// It will receive: title, name, email, response, comments, and submit.
//Adjust for registered_globals being off.
/* Subject and E-mail Variables */
$email_subject = 'Performance Training Registration';
$email_addresses = 'danieljolivas@gmail.com';
/* Gathers Data Variables */
// General Information
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$alt_phone = $_POST['alt_phone'];
$email = $_POST['email'];
// Fitness Information
$gender = $_POST['gender'];
$weight = $_POST['weight'];
$age = $_POST['age'];
$height_ft = $_POST['height_ft'];
$height_in = $_POST['height_in'];
$waist = $_POST['waist'];
$goal = $_POST['goal'];
// Do you belong to a gym?
$membership = $_POST['membership'];
$what_gym = $_POST['what_gym'];
$member_length = $_POST['member_length'];
$days_attend = $_POST['days_attend'];
$join_gym = $_POST['join_gym'];
// Are you an athlete?
$athlete = $_POST['athlete'];
$what_sport = $_POST['what_sport'];
$play_level = $_POST['play_level'];
$improve_what = $_POST['improve_what'];
$improve_other = $_POST['improve_other'];
// Why are you interested in Performance training?
$weight_loss = $_POST['weight_loss'];
$goal_weight = $_POST['goal_weight'];
$strength = $_POST['strength'];
$tone = $_POST['tone'];
$flexibility = $_POST['flexibility'];
$health_reasons = $_POST['health_reasons'];
// What Equipment will you have available (if any)?
$gym_membership = $_POST['gym_membership'];
$medicine_ball = $_POST['medicine_ball'];
$home_gym = $_POST['home_gym'];
$stability_ball = $_POST['stability_ball'];
$agility_ladder = $_POST['agility_ladder'];
$dumbbells = $_POST['dumbbells'];
$equip_other = $_POST['equip_other'];
$other_equipment = $_POST['other_equipment'];
// What is your cardio preference (if any)?
$c_walk = $_POST['c_walk'];
$c_run = $_POST['c_run'];
$c_hike = $_POST['c_hike'];
$c_skate = $_POST['c_skate'];
$c_bike = $_POST['c_bike'];
$c_swim = $_POST['c_swim'];
$c_stairs = $_POST['c_stairs'];
$exercise_history = $_POST['exercise_history'];
$devote_days = $_POST['devote_days'];
$devote_min = $_POST['devote_min'];
//Personal
$race = $_POST['race'];
$sleep = $_POST['sleep'];
// Medical Information
$med_exam = $_POST['med_exam'];
$heart = $_POST['heart'];
$lung = $_POST['lung'];
$digestive = $_POST['digestive'];
$diabetes = $_POST['diabetes'];
$prescriptions = $_POST['prescriptions'];
$drugs = $_POST['drugs'];
$asthma = $_POST['asthma'];
$inhaler_amount = $_POST['inhaler_amount'];
// Dietary Information
$breakfast = $_POST['breakfast'];
$meals = $_POST['meals'];
$fruit_veg = $_POST['fruit_veg'];
$fats = $_POST['fats'];
$processed_food = $_POST['processed_food'];
$alcohol = $_POST['alcohol'];
// Psychological Information
$happiness = $_POST['happiness'];
$depression = $_POST['depression'];
$anxiety = $_POST['anxiety'];
$relaxation = $_POST['relaxation'];
$marriage = $_POST['marriage'];
$job = $_POST['job'];
$comments = $_POST['comments'];
// PT Package Types
$high_school_training = $_POST['high_school_training'];
$target_training = $_POST['target_training'];
$pt1_training = $_POST['pt1_training'];
$professional_training = $_POST['professional_training'];
$elite_training = $_POST['elite_training'];
$body = <<<EOD
<br><hr><br>
<strong> General Information </strong>
First Name: $first_name <br>
Last Name: $last_name <br>
Address: $address <br>
City: $city <br>
State: $state <br>
Zip: $zip <br>
Country: $country <br>
Phone: $phone <br>
Alt. Phone: $alt_phone <br>
Email: $email <br>
<br>
<strong>Fitness Information</strong>
<br>
Gender: $gender <br>
Weight: $weight <br>
Age: $age <br>
Height ft: $height_ft <br>
Height in: $height_in <br>
Waist: $waist <br>
Goal: $goal <br>
<br>
<strong>Do you belong to a gym?</strong>
<br>
What Gym: $what_gym <br>
Member Length: $member_length <br>
Days Attend: $days_attend <br>
Are You Willing to Join a Gym?: $join_gym <br>
<br>
<strong>Are you an athlete?</strong>
<br>
What Sport: $what_sport <br>
Play Level: $play_level <br>
Improve What: $improve_what <br>
Improve Other: $improve_other <br>
<br>
<strong>Why are you interested in Performance Training?</strong>
Weight Loss: $weight_loss <br>
Goal Weight: $goal_weight <br>
Strength: $strength <br>
Tone: $tone <br>
Flexibility: $flexibility <br>
Health Reasons: $health_reasons <br>
<br>
<strong>What equipment will you have available (If any)?</strong>
<br>
Gym Membership: $gym_membership <br>
Medicine Ball: $medicine_ball <br>
Home Gym: $home_gym <br>
Stability Ball: $stability_ball <br>
Agility Ladder: $agility_ladder <br>
Weights/dumbbells: $dumbbells <br>
Other: $equip_other <br>
Other Equipment: $other_equipment <br>
<br>
<strong>What is your cardio preference (if any)?</strong>
<br>
Walk: $c_walk<br>
Run: $c_run <br>
Hike: $c_hike <br>
Skate: $c_skate <br>
Bike: $c_bike <br>
Swim: $c_swim <br>
Stairs: $c_stairs <br>
<br>
<strong>Performance Training package</strong>
<br>
High School Package: $high_school_training <br>
Target Training Package: $target_training <br>
PT1 Training Package: $pt1_training <br>
Professional Package: $professional_training <br>
Elite Training Package: $elite_training <br>
<br>
<strong>Fitness Schedule</strong>
<br>
How Active Are you?: $exercise_history <br>
Devote Days: $devote_days <br>
Devote Min: $devote_min <br>
<br>
<strong>Personal Information</strong>
<br>
Race: $race <br>
Sleep: $sleep <br>
<br>
<strong>Medical Information</strong>
<br>
Medical Exams: $med_exam <br>
Heart: $heart <br>
Lung: $lung <br>
Digestive: $digestive <br>
Diabetes: $diabetes <br>
Drugs: $drugs <br>
Prescriptions: $prescriptions <br>
Asthma: $asthma <br>
Inhaler Amount: $inhaler_amount <br>
<br>
<strong>Dietary Information</strong>
<br>
Breakfast: $breakfast <br>
Meals: $meals <br>
Fruit and Vegetables: $fruit_veg <br>
Fats: $fats <br>
Processed Food: $processed_food <br>
Alcohol: $alcohol <br>
<br>
<strong>Psychological Information</strong>
<br>
Happiness: $happiness <br>
Depression: $depression <br>
Anxiety: $anxiety <br>
Relaxation: $relaxation <br>
Marriage: $marriage <br>
Job: $job <br>
Comments: $comments <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($email_addresses, $email_subject, $body, $headers);
Its weird because i have another table in the database that is somewhat similar to the previous code, except there is less of it and I get responses from the e-mails no problem. Its almost the same coding.
Not sure exactly how it was if you had the name before the address or vice-versa...
Instead of the line you have for the FROM Headers.
Not sure this is the issue, but I know you should also include a Name in the from header.
Also there may be a lot other issues with sending out emails like this, whether your MTA is running or not, etc etc etc. But I assume all those are in place in your case.
Thank you for your reply, although, i must of worded it wrong. This code is supposed to send me an e-mail of the web form they submitted on my site. The from headers is supposed to indicate the client's e-mail address, not mine. I've been constantly testing the code but, still no go.
Tech_Face wrote:Thank you for your reply, although, i must of worded it wrong. This code is supposed to send me an e-mail of the web form they submitted on my site. The from headers is supposed to indicate the client's e-mail address, not mine. I've been constantly testing the code but, still no go.
Well I guess it's time you check to see if you have any MTA present in your server. Otherwise you can't use the mail function.
Who is your email provider, and do they have any spam controls on? 'Cos what you do, setting the From address as the user is going to trip them ("This email claims to come from gmail and really comes from a server at ineverheardofyou.com?") Use an email from your server as From and if you must, set the Reply-To header as their email.
Basically, Email sending is fraught with anti-spam traps you can so easily fall into.
Tech_Face wrote:Thank you for your reply, although, i must of worded it wrong. This code is supposed to send me an e-mail of the web form they submitted on my site. The from headers is supposed to indicate the client's e-mail address, not mine. I've been constantly testing the code but, still no go.
Well I guess it's time you check to see if you have any MTA present in your server. Otherwise you can't use the mail function.
I adjusted the code an alternate way and it worked for the e-mail address on my webserver but, not for the email provider email addresses, weird. Is there anyway I can adjust this in the code or do i have to set something in my email provider(gmail) settings?