php新手,邮件发送但发送空邮件。它不检查值
<?php
if(isset($_POST['submit'])){
$to = "info@tere.com"; // this is your Email address
$email = $_POST['email']; // this is the sender's Email address
$name = $_POST['name'];
$company = $_POST['company'];
$message = $name . " " . $email . " ". $company;
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$message,$headers);
mail($from,$headers2,$headers2,$message); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
我想我不是在检查values.alute值,当我在表单中添加它们时,它们出现在邮件的主题中。
答案 0 :(得分:0)
您可以尝试以下操作:
$message= wordwrap($message,70);
这是因为要求将消息包装为70个字符。
答案 1 :(得分:0)
我建议在前端验证表单,但是无论如何,您始终可以使用以下方法检查值是否为空:
if("" != trim($_POST['email']) && "" != trim($_POST['name']) && "" != trim($_POST['company'])){
//Here all the values are present and not empty
$company = $_POST['company'];
$name = $_POST['name'];
$user_email = $_POST['email'];
$to = "info@tere.com"; // this is your Email address
$message = $name . " " . $user_email . " ". $company;
$subject = 'SUBJECT OF EMAIL';
$headers = 'From: info@tere.com' . "\r\n" .
'Reply-To: info@tere.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);// send email to yourself
mail($user_email, $subject, $message, $headers);// send email to client
echo "Mail Sent. Thank you " . $user_email . ", we will contact you shortly.";
}else{
//Here one of the values is empty
echo "Email not sent!";
}
更新
复制以下几行并将其放在代码的顶部,看看是否有任何错误!
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);