所以我有一个带有表单的网页,我试图设置一个php页面,当点击提交按钮时,它会将所有表单信息发送到我的电子邮件,而无需用户使用Outlook或任何类型的电子邮件软件。我以为我做得对,但它不是运行PHP,而是显示所有PHP代码的页面,而且没有任何内容到达我的电子邮件。这是以下形式:
<form name="infoForm" method="post" action="email.php">
<p class="form">
Are you a registered voter in the state of Washington?<br>
<input type="checkbox" id="yesBox"/> Yes<br><br>
First Name: <input type="text" id="firstName"><br>
Last Name:<input type="text" id="lastName"><br><br>
Email: <input type="text" id="email" size="30"><br><br>
Street Address: <input type="text" id="street1" size="30"><br>
<input type="text" id="street2" size="30"><br>
City: <input type="text" id="city" size="30"><br>
State: <input type="text" id="state" size="30"><br>
Zip Code: <input type="text" id="zip" size="30"><br><br>
Initials: <input type="text" id="initials" size="3"><br><br>
<input type="submit" name="send" class="inputButton" id="send" value="Submit" disabled=true/> <input type="reset" name="resetFields" class="inputButton" value="Reset"/>
</p>
</form>
我的php代码:
<?php
if(isset($_POST['send'])){
$to_address="tonybenwhite@live.com";
$subject="WSA Day of Action Entry";
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$street1=$_POST['street1'];
$street2=$_POST['street2'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];
$initials=$_POST['initials'];
$message="Name: " .$firstname." ".$lastname."\n";
$message .="Email: " .$email."\n";
$message .="Street: " .$street1."\n";
$message .="Street: " .$street2."\n";
$message .="City: " .$city."\n";
$message .="State: " .$state."\n";
$message .="Zip Code: " .$zip."\n";
$message .="Initials: " .$initials."\n";
$headers = 'From: '.$email."\r\n".
'Replay-To: '.$email."\r\n".
'X-Mailer: PHP/' .phpversion();
mail($to_address, $subject, $message, $headers);
}
?><!DOCTYPE HTML>
<html>
<body>
Thank you!
</body>
</html>
答案 0 :(得分:3)
您必须将此内容类型用作text / html
if(isset($_POST['send'])){
$to_address="tonybenwhite@live.com";
$subject="WSA Day of Action Entry";
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$street1=$_POST['street1'];
$street2=$_POST['street2'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];
$initials=$_POST['initials'];
$message="Name: " .$firstname." ".$lastname."\n";
$message .="Email: " .$email."\n";
$message .="Street: " .$street1."\n";
$message .="Street: " .$street2."\n";
$message .="City: " .$city."\n";
$message .="State: " .$state."\n";
$message .="Zip Code: " .$zip."\n";
$message .="Initials: " .$initials."\n";
$headers=" From : ". $email."\r\n";
$headers.= 'MIME-Version: 1.0' . "\r\n";
$headers.= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to_address, $subject, $message, $headers);
}
答案 1 :(得分:0)
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$to_address1="Your mail id";
mail($to_address1, $subject, $message, $headers);
添加此
答案 2 :(得分:0)
使用PHP发送邮件有点棘手。在我切换到使用此插件之前,我遇到了很多问题:http://phpmailer.worxware.com/
如果你无法使它成功,你一定要试一试。
答案 3 :(得分:0)
我个人最近暂时设置了一封PHP电子邮件,然后才转换到.Net,我不确定你的代码究竟是什么问题,但这是我修改过的PHP电子邮件论坛,效果很好。 (已测试)