[英]How do you get php to send an email
我在 flutter 中有一个前端,它发送数据以更新 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
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/phpmailer/phpmailer/src/Exception.php';
require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/phpmailer/src/SMTP.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->SMTPDebug = 1;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->Host = "smtp.gmail.com";
$mail->Username = "xxxxxxxx@email.com";
$mail->Password = "xxxxxxxxxxxxxxx";
$mail->IsHTML(true);
$mail->AddAddress($to, "recipient-name");
$mail->SetFrom("xxxxxxxxx@email.com", "from-name");
$mail->AddReplyTo("xxxxxxxxx@email.com", "reply-to-name");
$mail->Subject = $subject;
$mail->MsgHTML($editor);
if (!$mail->Send()) {
echo "Error while sending Email.";
var_dump($mail);
} else {
echo "Email sent successfully";
}
用于在您的计算机上设置发送邮件。 我没有使用 PHPmailer。 我使用了邮件()。 尽管如此,根据操作系统,您必须对 UNIX 或 Linux 脚本有所了解。 您还必须搜索(如谷歌搜索)“如何在 Mac 上设置发送邮件(进入操作系统)”。 下面提到的链接对我有帮助:
https://gist.github.com/hacks/7ec2fe500332a6d23ee68d1c1a2279d5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.