我使用joomla,特别是我使用扩展源代码将代码添加到现有文章中。
我正在制作一个问卷,通过电子邮件将结果发回给用户。
问题是,php邮件功能不起作用,我无法弄清楚原因。
这是我的代码:
<?php
ini_set('display_errors',1);
ob_start();
if(isset($_POST['btnSubmit'])) {
if(isset($_POST['contact_name']) && isset($_POST['contact_email']) && isset($_POST['q1']) && isset($_POST['q2']) && isset($_POST['q3'])) {
$contact_name = $_POST['contact_name'];
$contact_email = $_POST['contact_email'];
}
if(!empty($contact_name) && !empty($contact_email)) {
if (strlen($contact_name)<35 && strlen($contact_email)<50) {
echo $contact_name;
echo '<br>';
echo $contact_email;
echo '<br>';
$q1 = $_POST['q1'];
if ($q1 == 1) {$q1a = "Blank Answer A";} ;
if ($q1 == 2) {$q1a = "Blank Answer B";} ;
if ($q1 == 3) {$q1a = "Blank Answer C";} ;
echo $q1a;
echo '<br>';
$q2 = $_POST['q2'];
if ($q2 == 1) {$q2a = "Blank Answer A";} ;
if ($q2 == 2) {$q2a = "Blank Answer B";} ;
if ($q2 == 3) {$q2a = "Blank Answer C";} ;
echo $q2a;
echo '<br>';
$q3 = $_POST['q3'];
if ($q3 == 1) {$q3a = "Blank Answer A";} ;
if ($q3 == 2) {$q3a = "Blank Answer B";} ;
if ($q3 == 3) {$q3a = "Blank Answer C";} ;
echo $q3a;
echo '<br>';
$to = $contact_email;
$subject = 'Your questionnaire results';
$message = 'This is a test email'."\n\n".'Hope you got it.';
$headers = 'From: email@email.com';
if (@mail($to, $subject, $message, $headers)) {
echo 'Your results have been sent by email.';
exit();
} else {
echo 'There was an error sending your results.';
}
}
else {
echo 'Error: Max length of name or e-mail field exceeded.';
}
} else {
echo "Error: Missing Fields";
}
}
?>
<form name="frm1" action="8-beginners" method="POST">
Name:<br> <input type="text" name="contact_name" id="contact_name" maxlength="34" ><br><br>
E-Mail Address:<br> <input type="text" name="contact_email" id="contact_email" maxlength="49" ><br><br>
question 1:<br>
<input type="radio" name="q1" value="1" /> Answer 1<br>
<input type="radio" name="q1" value="2" /> Answer 2<br>
<input type="radio" name="q1" value="3" /> Answer 3<br><br>
question 2:<br>
<input type="radio" name="q2" value="1" /> Answer 1<br>
<input type="radio" name="q2" value="2" /> Answer 2<br>
<input type="radio" name="q2" value="3" /> Answer 3<br><br>
question 3:<br>
<input type="radio" name="q3" value="1" /> Answer 1<br>
<input type="radio" name="q3" value="2" /> Answer 2<br>
<input type="radio" name="q3" value="3" /> Answer 3<br> <br>
<br>
<input type="submit" name="btnSubmit" value="Submit Form" />
</form>
答案 0 :(得分:0)
您的代码是在localhost还是在服务器上?如果在localhost上 - 你有没有启动本地smtp?
我将从邮件功能中删除@并查看是否发生了一些错误。