大家好我在这里有一个表单,当添加新联系人时会向某人发送电子邮件。
一切正常。用户被添加到数据库,电子邮件被发送但电子邮件是空白的:
EG。员工: 延期: 电子邮件: 手机:
我尝试了几种方法,电子邮件总是空白,如果有可能有人可以提供帮助吗?
我的代码:
\/\K((\d{1,2}\.)+)\d{1,2}
答案 0 :(得分:2)
问题是你执行这一行:
mail($to,$subject,$message,$headers);
在声明它所依赖的变量之前。只有在代码的后面才能设置它们
$name = $_POST['name'];
$email = $_POST['email'];
$department = $_POST['department'];
...
可以在mail
函数
if(isset($_POST['submit'])):
$name = $_POST['name'];
...
mail(...);
endif;
答案 1 :(得分:0)
以下是您的代码
$message = "New Staff: " . "\n\n" . "Name : " . $name . " " . "\n\n" . "Email: " . $email . " " . "\n\n" . "Department: " . $department . " " . "\n\n" . "Extension: " . $extension . " " . "\n\n" . "Cellphone: " . $
最后有一个$
符号。我认为这是一个错误。
请将其重写为
$message = "New Staff: " . "\n\n" . "Name : " . $name . " " . "\n\n" . "Email: " . $email . " " . "\n\n" . "Department: " . $department . " " . "\n\n" . "Extension: " . $extension . " " . "\n\n" . "Cellphone: " . $Your_value_if_any;
重要提示:在sql之后添加您的电子邮件代码。没有为$name
,$email
等许多变量分配值。
答案 2 :(得分:0)
我在上面创建了上面的代码。它工作得很完美。请检查一下。
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$insert_contact = "insert into name (name) values ('$name')";
$sql_insert_contact = $conn->query($insert_contact);
$to = "To email";
$from = "From Email";
$subject = "New Staff Added To Extension List";
$message = "New Staff: " . "\n\n" . "Name : " . $name;
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
header("Location: index.php");
}