PHP邮件表单不起作用 [英] PHP mail form isn't working

查看:57
本文介绍了PHP邮件表单不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的HTML: 全名

My HTML: Full Name

<div class="row">
<div class="label"> Age </div>
<div class="input">
<input type="text" id="age" class="detail" name="age" value="" />
</div>
</div>

<div class="row">
<div class="label"> Gender </div>
<div class="input">
Male:<input type="radio" id="radio1"   name="gender" value="" />
Female:<input type="radio" id="radio2" name="gender" value="" />
</div>
</div>

<div class="row">
<div class="label"> Department </div>
<div class="select">
<select id="department" class="detail" name="department" value="" />
<option>Please select below</option>
<option>xxxx</option>
<option>xxxx</option>
</select>
</div>
</div>

<div class="row">
<div class="label"> Who do you want to consult </div>
<div class="select">
<select id="consult" class="detail" name="consult" value="" />
<option>xxxx</option>
<option>xxxx</option>
<option>xxxxy</option>
<option>xxxxx</option>
<option>xxx</option>
<option>xxxxx</option>
</select>
</div>
</div>


<div class="row">
<div class="label"> When do you want to visit us</div>
<div class="date">
<input type="date" id="date" class="detail" name="date" value="" />
</div>
</div>

<div class="row">
<div class="label"> Do you have any specific requests or needs</div>
<div class="request">
<input type="text" id="request" class="detail" name="request" value="" />
</div>
</div>

<div class="row">
<div class="label"> When is a good time to call you</div>
<div class="time">
<input type="time" id="time" class="detail" name="time" value="">
</div>
</div>


<div class="row">
<div class="label"> E-mail </div>
<div class="input">
<input type="email" id="email" class="detail" name="email" value="" />
</div>
</div>

<div class="row">
<div class="label"> Phone number </div>
<div class="input">
<input type="tel" id="tel" class="detail" name="tel" value="">
</div>
</div>


<div id="submit-reset">
<input type="submit" id="submit" name="submit" value="Submit Form" />
<input type="reset" id="reset" name="reset" value="Reset" />
</div>
</form>

我很难为此配置PHP部分 我的PHP代码:

I'm having hard time configuring PHP part for this My PHP code:

$fullname = $_POST['fullname'];
$age = $_POST['age'];
$gender = $_POST['gender'];
$department = $_POST['department'];
$consult = $_POST['consult'];
$date = $_POST['date'];
$request = $_POST['request'];
$time = $_POST['time'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$to = "example@email.com";
$subject = "message goes here";

mail ($to, $subject, "From: " .$fullname);
echo "message sent"
?>

使用我的邮件ID进行测试时,它表明已发送邮件,但我根本没有收到任何邮件.请帮我解决这个问题.我是一个菜鸟到php,所以我根本不知道它是如何工作的:( 同样,任何有关验证的内容也将不胜感激.

When tested with my mail ID it shows that message is sent, but i am not receiving any mail at all. Please help me out on this. I ama rookie to php so i dno't know how it works at all :( Also any regarding validation would be much appreciated.

推荐答案

我认为您需要在服务器上添加发件人"作为地址,并放置回复"标题,以便在收件箱中收到电子邮件时可以以正常方式回复.

I think you need to add the From as an address on your server and put a Reply-to header so that when you get the email in your inbox you can reply to it in the normal way.

据我所知,而不是服务器上的发件人",您从表单中获得了他们的全名.

As far as I can see instead of a From on your server you have their full name from the form.

在消息部分引用@ nana-partykar-从$message开始替换为:

To quote @nana-partykar for the message part - replace from $message onwards with:

    $message="Name: ".$fullname."<br/>Age: ".$age,"<br/>Gender",$gender."<br/>Phone".$phone."<br/>Dept:".$department;

    $your_email = 'your_email@your_server.com';
    $headers = "From: $your_email" . "\r\n";
    // Additional headers
    $headers .= "Reply-To: $email" . "\r\n";
    if(mail($to,$subject,$message,$headers)){
    echo "Success";
    } else {
    echo "not sent";
    }

http://php.net/manual/en/function.mail.php

您也可以尝试在脚本顶部设置sendmail用户:

You could also try setting the sendmail user at the top of your script:

    ini_set('sendmail_from', 'your_email@your_server.com'); 

http://php.net/manual/zh/book.mail.php

就验证而言,您可以清理提交的内容,仅允许使用字母,数字和其他一些字符:

As far as validation is concerned you could clean up what is submitted to allow only letters, numbers and a few other characters:

    $email = preg_replace("[^a-zA-Z0-9@._-]",'',$_POST['email']);

,并通过将邮件部分包装为以下内容,至少确保基本电子邮件地址不为空:

and at least make sure that the essential email address is not empty by wrapping the mail part with:

    if($email != ""){

    if(mail....to the end

    }

如果要将接收到的任何信息放入数据库中,则需要确保它也没有注入攻击代码

If you are putting any of the received information into a database you need to ensure it is also free of inject attack code

如何防止PHP中的SQL注入?

我建议您先这样做,然后再做!

I would suggest getting it working first before you do that...but do do it!

这篇关于PHP邮件表单不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆