首页 > 解决方案 > 你如何让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);
      
        }
    }
    
?>

标签: php

解决方案


用于在您的计算机上设置发送邮件。我没有使用 PHPmailer。我使用了邮件()。不过,您必须对 UNIX 或 Linux 脚本有所了解——根据操作系统。您还必须搜索(如谷歌搜索)“如何在 Mac 上设置发送邮件(进入操作系统)”。下面提到的链接对我有帮助:

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

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


推荐阅读