Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让php发送电子邮件_Php - Fatal编程技术网

如何让php发送电子邮件

如何让php发送电子邮件,php,Php,我在Flatter中有一个前端,它用php发送数据以更新mysql数据库。表单发送数据,数据库更新得很好。但是,它绕过或忽略发送邮件的部分。我没有收到任何邮件错误。我做错了什么 <?php require_once('dbc.php'); $name = $_POST["name"]; $email= $_POST["email"]; $phone= $_POST["phone"

我在Flatter中有一个前端,它用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。我使用了mail()。不过,您必须对UNIX或Linux脚本有所了解——根据操作系统的不同。您还必须搜索(如谷歌搜索)“如何设置在mac上发送邮件(输入操作系统)”。下面提到的链接帮助了我:


您需要配置SMTP。您提供的几乎所有详细信息都与您的问题无关。我们不关心您是否正在从Flatter访问它,如果数据库插入运行正常,那么该部分代码不会被“忽略”。您的实际代码是从
$to=…
到`mail(…);我想,您的问题是为什么没有收到生成的电子邮件。
$find exist
是一个无效的变量名。您的代码也可以接受SQL注入。参数化并使用准备好的语句。不建议使用本机PHP mailer函数。它的错误报告能力差。使用Swift或PHPMailer。可能需要更多信息。e、 g.
PHPMailer.php
SMTP.php
Exception.php
对于初学者来说,仍然不起作用。它不会做任何事。一旦insert查询运行,它将查找json返回。它忽略邮件部分。iI如果您使用Gmail,您需要授予应用程序权限,并且composer需要phpmailer/phpmailerMalek,我将下载composer并将其移动到我的网站文件夹中。它被称为PHPMailer。不知道我做错了什么。我没有错。我需要最好的方法来完成这项工作。我读到,如果我没有收到任何电子邮件,最有可能的谷歌块端口25。我不确定那是真的。我曾经收到一封电子邮件,说有人访问或试图访问我的帐户。现在我没有得到任何承认。PHMailer没有任何区别。同样的事情正在发生。