/    Sign up×
Community /Pin to ProfileBookmark

problems generating an email from captured form data

Hi,

This is my first attempt at PHP, so hopefully, you’ll go easy on me.

I have an form that calls a .php file. The php file is supposed to generate an email made up of the captured form fields and redirect the user to a ‘thank you’ page. The redirect works, but the email is not being generated.

Here is my code:

[Code]

<?PHP putenv(“TZ=US/Central”); $time = date(“M j, Y, g:i a”);

$name = $_POST[“name”];
$email = $_POST[“email”];
$phone = $_POST[“phone”];
$contact = $_POST[“contact”];
$destination = $_POST[“destination”];
$resort_brand = $_POST[“resort_brand”];
$specific_resort = $_POST[“specific_resort”];
$specialty_vacation = $_POST[“specialty_vacation”];
$cruise_line = $_POST[“cruise_line”];
$cruise_destination = $_POST[“cruise_destination”];
$cruise_duration = $_POST[“cruise_duration”];
$departDate = $_POST[“departDate”];
$number_adults = $_POST[“number_adults”];
$number_of_nights = $_POST[“number_of_nights”];
$number_children = $_POST[“number_children”];
$age1 = $_POST[“age1”];
$age2 = $_POST[“age2”];
$age3 = $_POST[“age3”];
$age4 = $_POST[“age4”];
$age5 = $_POST[“age5”];
$passport = $_POST[“passport”];
$handicapped = $_POST[“handicapped”];
$comments = $_POST[“comments”];

$recipient = “[email protected], [email protected], [email protected]”;
$subject = “Classic Travel quote request”;

$body = “<p><b>Name:</b> $name<p><b>Email:</b> $email<p><b>Phone:</b> $phone<p><b>Contact:</b> $contact<p><b>Destination:</b> $destination<p><b>Resort Brand:</b> $resort_brand<p><b>Specific Resort:</b> $specific_resort<p><b>Specialty Vacation:</b> $specialty_vacation<p><b>Cruise Line:</b> $cruise_line<p><b>Cruise Destination:</b> $cruise_destination<p><b>Cruise Duration:</b> $cruise_duration<p><b>Departure Date:</b> $departDate<p><b>Number of Adults:</b> $number_adults<p><b>Number of Nights:</b> $number_of_nights<p><b>Number of Children:</b> $number_children<p><b>Age1:</b> $age1<p><b>Age2:</b> $age2<p><b>Age3:</b> $age3<p><b>Age4:</b> $age4<p><b>Age5:</b> $age5<p><b>Passport:</b> $passport<p><b>Handicapped:</b> $handicapped<p><b>Comments:</b> $comments”;

$headers = “From: “$name” <$email>rn”;
$headers .= “MIME-Version: 1.0rn”;
$headers .= “X-Mailer: Drupaln”;
$headers .= ‘MIME-Version: 1.0’ . “n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “rn”;

$send = mail($recipient,$subject,$body,$headers);

header( “Location: http://dmsgroup.co/classic-travel/thank_you.html” ) ;

?>
[/code]

The form that calls this file is here: [url]http://dmsgroup.co/classic-travel/request_info.html[/url]

It was working at one point, but it’s not anymore. Also, when it was working, the “specialty_vacation” field (which is a checkbox) would not pull in any data. Do I need to do something different to access checkboxes?

Thanks in advance for your help!

SteveMTNO

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@OctoberWindMar 16.2011 — [code=php]
$send = mail($recipient,$subject,$body,$headers);
[/code]


You're declaring the mail() function to a variable, but you're not doing anything with it.

Try something like this:

[code=php]
$send = mail($recipient,$subject,$body,$headers);

if ($send) // if the mail handler returns a TRUE
{
header( "Location: http://dmsgroup.co/classic-travel/thank_you.html" ) ;
}
else
{
echo "<h2>There was an error sending the e-mail.</h2>";
}
[/code]


Regarding the Specialty Vacations, if you want them to be grouped together (since you have them all named the same), then you need to append each form var's name with brackets[] to capture all the check boxes into any array. Otherwise you are just overwriting each previous value with the next. The alternative would be to give them all unique names, and handle each one separately. :x

From there, you can loop through the array to find the values that are checked, and toss them into a string.
[code=php]
$vacation_string = "";
foreach ($specialty_vacation as $value)
{
if ($value != ""){
$vacation_string .= "$value, ";
}

}
[/code]
Copy linkTweet thisAlerts:
@stevemtnoauthorMar 16.2011 — Hmmm, when I tried that, I got:

Warning: mail() [function.mail]: SMTP server response: 554 The message was rejected because it contains prohibited virus or spam content in D:Hosting6537521htmlclassic-travelsend_mail_Form.php on line 38
×

Success!

Help @stevemtno spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...