问题描述:

I'm fairly new to the world of php (3 days experience to be precise). I'm trying to send an email from a "Contact us" page and everything works fine, except the larger message or enquiry, any help would be mighty fine!

<div class="form-group required">

<label class="col-sm-2 control-label" for="input-enquiry">

<?php echo $entry_enquiry; ?>

</label>

<div class="col-sm-10">

<textarea name="enquiry" rows="10" id="input-enquiry" class="form-control" style="font:;color:#333333"><?php echo $enquiry; ?></textarea>

<?php if ($error_enquiry) { ?>

<div class="text-danger"><?php echo $error_enquiry; ?></div>

<?php } ?>

</div>

</div>

And here is the code for sending the email

<div class="buttons">

<div class="pull-right">

<input class="button btn btn-theme-default" type="submit"

value="<?php $to='[email protected]';

$subject='Message from Contacs us';

mail($to, $subject, $enquiry, "From:".$email);

echo $button_submit;

?>" />

</div>

</div>

网友答案:

That's not how HTML and PHP work - you're sending a mail every time you render the submit button of that form.

The call to mail() actually performs the "send mail" action as soon as it's hit by the interpreter.

What you need to do is have a function which tests the form data, then if-and-only-if the data are valid, sends the mail and redirects you to a thank-you page (or renders it itself).

相关阅读:
Top