任何人都可以看到我的PHP表单发件人代码有什么问题:??
我的代码列在下面 - 表单总是说不管是什么,不正确的电子邮件地址。因此,它被打破了。非常感谢你的帮助!
$to = "joinrendezvous@gmail.com";
$from = "mail@example.com";
$headers = "From: " . $from . "\r\n";
$subject = "New subscription";
$body = "New user subscription: " . $_POST['email'];
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
if (mail($to, $subject, $body, $headers, "-f " . $from)) {
echo 'Alright ! You will be notified on <b> ' . $_POST['email'] . '</b> :)';
}
else {
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
}
else {
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
答案 0 :(得分:0)
什么是错误的电子邮件&amp;你想做什么?
看看这个:
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
if (mail($to, $subject, $body, $headers, "-f " . $from)) {
if
检查$_POST['email']
时,mail
命令正在使用$to
作为变量。咦?也许你的代码应该是:
if (filter_var($to, FILTER_VALIDATE_EMAIL)) {
if (mail($to, $subject, $body, $headers, "-f " . $from)) {
echo 'Alright ! You will be notified on <b> ' . $to . '</b> :)';
}
else {
echo 'There was a problem with your e-mail (' . $to . ')';
}
}
else {
echo 'There was a problem with your e-mail (' . $to . ')';
}
但是,如果您不打算使用$_POST
表单变量,为什么还要通过表单执行此操作?
答案 1 :(得分:0)
我认为问题是$ _POST ['email']。回复它,这样你就可以看到$ _POST ['email']的电子邮件格式是否正确,因为filter_var检查了..