通过php脚本发送html表单详细信息到一个电子邮件地址 [英] send html form details to an email address via php script
问题描述
嘿,我刚刚主持了我的第一个网站 http://www.phillipparker.co.uk ,但我的提交表单将转到空白网址 http://www.phillipparker.co.uk/submit.php ,但实际上并没有发送HTML格式的详细信息到指定的电子邮件。任何帮助将非常感谢我的Html表格代码如下:
< form name =form1method =postaction =submit.php>
< p>
< input name =Nametype =textid =Namesize =30>
< / p>
< p>
< input name =Emailtype =textid =Emailsize =30>
< / p>
< p>
< input name =联络号码type =textid =联络号码size =30>
< / p>
< p>
< label>
< input type =radioname =RadioGroupContactvalue =Phoneid =RadioGroupContact_0>
电话< / label>
< label>
< input type =radioname =RadioGroupContactvalue =Emailid =RadioGroupContact_1>
电邮< / label>
< / p>
< p>
< label>
< input type =radioname =RadioGroupTimevalue =Morningid =RadioGroupTime_0>
早晨< / label>
< label>
< input type =radioname =RadioGroupTimevalue =Afternoonid =RadioGroupTime_1>
下午< / label>
< label>
< input type =radioname =RadioGroupTimevalue =Eveningid =RadioGroupTime_2>
晚上< / label>
< br>
< / p>
< p>
< label for =Message>< / label>
< textarea name =Messageid =Messagecols =30rows =7>< / textarea>
< / p>
< p>
< input type =resetname =Clearid =Clearvalue =Clear>
< input name =Submittype =submitid =Submitformaction =submit.phpformmethod =POSTvalue =Submit>
< / p>
< / form>
< / div>
< / div>
我的PHP文件(submit.php)如下:
<?php
if(isset($ _ POST ['email'])){
$ email_to =4001 @ gmail.com;
$ email_subject =www.phillipparker.co.uk;
$联系人编号= $ _POST ['联系人编号']; //必需
$ email_from = $ _POST ['Email']; //必需
$名称= $ _POST ['Name']; //不需要
$ Message = $ _POST ['Message']; //必需
$ email_message =表格详情如下.\\\
\\\
;
$ b}
$ email_message。=联系电话:.clean_string($联系人号码)。\\\
;
$ email_message。=电子邮件:.clean_string($ email_from)。\\\
;
$ email_message。=名称:.clean_string($ Name)。\\\
;
$ email_message。=消息:.clean_string($ Message)。\\\
;
$ headers ='From:'。$ email_from。\r\\\
。
'回复:'。$ email_from。\r\\\
。
'X-Mailer:PHP /'。 phpversion();
@mail($ email_to,$ email_subject,$ email_message,$ headers);
?>
我仍然在更新我的submit.php文件,包括单选按钮,但我会更喜欢在我进行任何改动之前让联系页面正常工作。
预先致谢
在
<$ p $之前p> <?php
$ emailTo ='< YOUR@EMAIL.COM>';
if($ _ SERVER ['REQUEST_METHOD'] =='POST'){
$ name = stripslashes(trim($ _ POST ['form-name']));
$ email = stripslashes(trim($ _ POST ['form-email']));
$ subject = stripslashes(trim($ _ POST ['form-subject']));
$ message = stripslashes(trim($ _ POST ['form-message']));
$ emailIsValid = preg_match('/ ^ [^ 0-9] [A-z0-9 _] +([。] [A-z0-9 _] +)* [@] [A- z0-9 _] +([。] [A-z0-9_] +)* [。] [Az] {2,4} $ /',$ email); $
$ b if($ name&& $ email&& $ emailIsValid&& $ subject& $ message){
$ subject =[Contato via Site ] $ subject;
$ body =名称:$ name< br />电子邮件地址:$ email< br />电话号码:$ message< br />位置:$ subject;
$ headers ='MIME-Version:1.1'。 PHP_EOL;
$ headers。='Content-type:text / html; charset = utf-8'。 PHP_EOL;
$ headers。=From:$ name< $ email> 。 PHP_EOL;
$ headers。=Return-Path:$ emailTo。 PHP_EOL;
$ headers。=回复:$ email。 PHP_EOL;
邮件($ emailTo,$ subject,$ body,$ headers);
$ emailSent = true;
} else {
$ hasError = true;
}
}
?>
使用这个表单本身,然后自定义。
<?php if(isset($ emailSent)&& $ emailName):?>
< div class =col-md-6 col-md-offset-3>
< div class =alert alert-success text-center>谢谢! ADT代表会尽快与您联系。< / div>
< / div>
<?php else:?>
<?php if(isset($ hasError)&& $ hasError):?>
< div class =col-md-5 col-md-offset-4>
< div class =alert alert-danger text-center>嗯......看起来有错误,请再试一次,确保所有字段都已填写完毕。< / div>
< / div>
<?php endif; ?>
< div class =col-md-6 col-md-offset-3>
< form action =<?php echo $ _SERVER ['REQUEST_URI'];?> id =contact-formclass =form-horizontalrole =formmethod =poststyle =height:300px; padding-left:10px; padding-top:10px;>
< label for =namestyle =font-size:20px; padding-top:5px; padding-bottom:5px;>全名< / label>
< input type =textid =form-namename =form-nameplaceholder =John Smith/>
< label for =emailstyle =font-size:20px; padding-top:5px; padding-bottom:5px; >电子邮件与LT; /标签>
< input type =emailid =form-emailname =form-emailplaceholder =example@yourdomain.com/>
< label for =mensagemstyle =font-size:20px; padding-top:5px; padding-bottom:5px;> Phone Number< / label>
< input type =textid =form-messagename =form-messageplaceholder =555-234-8765/>
< label for =assuntostyle =font-size:20px; padding-top:5px; padding-bottom:5px;>城市与州< / label>
< input type =textid =form-subjectname =form-subjectplaceholder =Los Angeles,CA/>
< p style =font-size:7px;>点击呼叫我即表示我同意< a href =terms.html>条款和条件< / a>< / p为H.
< div class =modal-footer>
< button type =sumbitname =submitvalue =Submitclass =btn btn-primary> Call Me< / button>
Hey I have just hosted my first website http://www.phillipparker.co.uk but my submit form goes to a blank url http://www.phillipparker.co.uk/submit.php but doesnt actually send html form details to the email specified.Any help would be hugely apprecciated My Html Form code is as below:
<form name="form1" method="post" action="submit.php">
<p>
<input name="Name" type="text" id="Name" size="30">
</p>
<p>
<input name="Email" type="text" id="Email" size="30">
</p>
<p>
<input name="Contact number" type="text" id="Contact number" size="30">
</p>
<p>
<label>
<input type="radio" name="RadioGroupContact" value="Phone" id="RadioGroupContact_0">
Phone</label>
<label>
<input type="radio" name="RadioGroupContact" value="Email" id="RadioGroupContact_1">
Email</label>
</p>
<p>
<label>
<input type="radio" name="RadioGroupTime" value="Morning" id="RadioGroupTime_0">
Morning</label>
<label>
<input type="radio" name="RadioGroupTime" value="Afternoon" id="RadioGroupTime_1">
Afternoon</label>
<label>
<input type="radio" name="RadioGroupTime" value="Evening" id="RadioGroupTime_2">
Evening</label>
<br>
</p>
<p>
<label for="Message"></label>
<textarea name="Message" id="Message" cols="30" rows="7"></textarea>
</p>
<p>
<input type="reset" name="Clear" id="Clear" value="Clear">
<input name="Submit" type="submit" id="Submit" formaction="submit.php" formmethod="POST" value="Submit">
</p>
</form>
</div>
</div>
My Php file (submit.php) is as below:
<?php
if(isset($_POST['email'])) {
$email_to = "4001@gmail.com";
$email_subject = "www.phillipparker.co.uk";
$Contact_number = $_POST[' Contact number ']; // required
$email_from = $_POST['Email']; // required
$Name = $_POST['Name']; // not required
$Message = $_POST['Message']; // required
$email_message = "Form details below.\n\n";
}
$email_message .= "Contact Number: ".clean_string($Contact_number)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Name: ".clean_string($Name)."\n";
$email_message .= "Message: ".clean_string($Message)."\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
I am still in the process of updating my submit.php file i.e. including the radio buttons but i would prefer to get the contact page working before i make any alterations.
Thanks in advance
your PHP is a little messy.
Put this in the head before
<?php
$emailTo = '<YOUR@EMAIL.COM>';
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = stripslashes(trim($_POST['form-name']));
$email = stripslashes(trim($_POST['form-email']));
$subject = stripslashes(trim($_POST['form-subject']));
$message = stripslashes(trim($_POST['form-message']));
$emailIsValid = preg_match('/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0- 9_]+)*[.][A-z]{2,4}$/', $email);
if($name && $email && $emailIsValid && $subject && $message){
$subject = "[Contato via Site] $subject";
$body = "Name: $name <br /> Email: $email <br /> Phone Number: $message <br /> Location: $subject";
$headers = 'MIME-Version: 1.1' . PHP_EOL;
$headers .= 'Content-type: text/html; charset=utf-8' . PHP_EOL;
$headers .= "From: $name <$email>" . PHP_EOL;
$headers .= "Return-Path: $emailTo" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
} else {
$hasError = true;
}
}
?>
Use this for the form itself and customize however you please.
<?php if(isset($emailSent) && $emailSent): ?>
<div class="col-md-6 col-md-offset-3">
<div class="alert alert-success text-center">Thank You! An ADT representative will contact you shortly.</div>
</div>
<?php else: ?>
<?php if(isset($hasError) && $hasError): ?>
<div class="col-md-5 col-md-offset-4">
<div class="alert alert-danger text-center">Hmmm... It seems there was an error, please try again and make sure all the fields are filled out.</div>
</div>
<?php endif; ?>
<div class="col-md-6 col-md-offset-3">
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" id="contact-form" class="form-horizontal" role="form" method="post" style="height: 300px; padding-left:10px; padding-top:10px;">
<label for="name" style="font-size:20px; padding-top: 5px; padding-bottom: 5px;">Full Name</label>
<input type="text" id="form-name" name="form-name" placeholder="John Smith" />
<label for="email" style="font-size:20px; padding-top: 5px; padding-bottom: 5px;" >Email</label>
<input type="email" id="form-email" name="form-email" placeholder="example@yourdomain.com" />
<label for="mensagem" style="font-size:20px; padding-top: 5px; padding-bottom: 5px;">Phone Number</label>
<input type="text" id="form-message" name="form-message" placeholder="555-234-8765" />
<label for="assunto" style="font-size:20px; padding-top: 5px; padding-bottom: 5px;">City and State</label>
<input type="text" id="form-subject" name="form-subject" placeholder="Los Angeles, CA" />
<p style="font-size: 7px;">By clicking "Call Me" I agree to the <a href="terms.html">Terms and Conditions</a></p>
<div class="modal-footer">
<button type="sumbit" name="submit" value="Submit" class="btn btn-primary">Call Me</button>
这篇关于通过php脚本发送html表单详细信息到一个电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!