php - 你如何让php发送电子邮件
问题描述
我有一个颤振的前端,它发送数据以更新 php 中的 mysql 数据库。表单发送数据并且数据库更新得很好。但是,它绕过或忽略了发送邮件的部分。我没有收到任何邮件错误。做错了什么?
<?php
require_once('dbc.php');
$name = $_POST["name"];
$email= $_POST["email"];
$phone= $_POST["phone"];
$password = $_POST["password"];
$findexist="select * from registered where name='$name'";
$resultsearch=mysqli_query($conn,$find-exist);
if(mysqli_num_rows($resultsearch)>0) {
while($row=mysqli_fetch_array($resultsearch)) {
$result["success"] = "3";
$result["message"] = "user Already exist";
echo json_encode($result);
mysqli_close($conn);
}
} else {
$sql = "INSERT INTO registered (name,email,phone,password) VALUES ('$name','$email','$phone','$password');";
if ( mysqli_query($conn, $sql) ) {
$result["success"] = "1";
$result["message"] = "Registration success";
echo json_encode($result);
$to = $email;
$subject = 'Signup | Verification';
$message = 'Thanks for signing up with redhowler!';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers = "Content-Type: text/html; charset=utf-8" . "\r\n";
$headers .= 'From: redhowler2@gmail.com'. "\r\n";
mail($to, $subject, $message, $headers);
mysqli_close($conn);
}
}
?>
解决方案
用于在您的计算机上设置发送邮件。我没有使用 PHPmailer。我使用了邮件()。不过,您必须对 UNIX 或 Linux 脚本有所了解——根据操作系统。您还必须搜索(如谷歌搜索)“如何在 Mac 上设置发送邮件(进入操作系统)”。下面提到的链接对我有帮助:
https://gist.github.com/hacks/7ec2fe500332a6d23ee68d1c1a2279d5
推荐阅读
- php - Codeigniter - Implode 生成的查询返回“未知列”
- wso2 - 使用 WSO2 API 管理器的最佳方式
- python - 如何更改 matplotlib AxisSubplot 的颜色?
- sql - 按多列分组并将结果作为单独列中的数组获取
- python - 尝试读取 .tsv 文件,其中前几行包含与文件其余部分不同的字段数量
- c++ - 有选择地禁用库中的死代码消除
- apache-cayenne - Apache Cayenne 是否可以在没有数据库的情况下预填充 ObjectContext?
- windows - Windows:如何绕过桌面窗口管理器并直接绘制到前端缓冲区?
- docker - 如何在 Docker 中分配容器特定的 IPv4 和 IPv6 地址
- php - VM2714:1 未捕获的 SyntaxError:位置 0 处 JSON 中的意外标记 d