简体   繁体   English

你如何得到 php 发送一个 email

[英]How do you get php to send an email

I have a frontend in flutter that sends data to update mysql database in php.我在 flutter 中有一个前端,它发送数据以更新 php 中的 mysql 数据库。 The form sends the data and the database updated just fine.表单发送数据并且数据库更新得很好。 However, it is bypassing or ignoring the section to send mail.但是,它绕过或忽略了发送邮件的部分。 I am not getting any errors for the mail.我没有收到任何邮件错误。 What am doing wrong?做错了什么?

<?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);
      
        }
    }
    
?>

Try to use PHPMailer尝试使用 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";
        }

For setting up send mail on your computer.用于在您的计算机上设置发送邮件。 I didn't use PHPmailer.我没有使用 PHPmailer。 I used mail().我使用了邮件()。 Nevertheless, you have to have some knowledge of UNIX or Linux script -- according to the operating system.尽管如此,根据操作系统,您必须对 UNIX 或 Linux 脚本有所了解。 You also have to search(like google search) for "how to setup send mail on mac (enter operating system)".您还必须搜索(如谷歌搜索)“如何在 Mac 上设置发送邮件(进入操作系统)”。 Links such as those mention below helped me:下面提到的链接对我有帮助:

https://gist.github.com/haccks/7ec2fe500332a6d23ee68d1c1a2279d5 https://gist.github.com/hacks/7ec2fe500332a6d23ee68d1c1a2279d5

https://benjaminrojas.net/configuring-postfix-to-send-mail-from-mac-os-x-mountain-lion/#comment-87436 https://benjaminrojas.net/configuring-postfix-to-send-mail-from-mac-os-x-mountain-lion/#comment-87436

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM