PHP Mailer 发件人电子邮件与收件人电子邮件相同

问题描述 投票:0回答:1

我是 PHP 新手,我正在制作一个带有表单的页面。当客户填写输入字段中的所有信息并单击“提交”时,我会收到一封邮件。我面临的问题是,即使我在表单上输入不同的发件人电子邮件地址,当我单击“提交”按钮时,我收到的收件箱中的邮件原来是来自我的(即就像我发送的邮件一样)给我自己 - 即使表格上有不同的发件人电子邮件地址)。我已经尝试了一切我真的不知道我的问题出在哪里。 这是我的代码

<form action="send-mail.php" method="post">
            <div class="b-form__inputWrap">
                <label for="name">Name</label>
                <input name="name" id="name">
            </div>

            <div class="b-form__inputWrap">
                <label for="email">email</label>
                <input name="email" id="email">
            </div>

            <div class="b-form__inputWrap">
                <label for="name">Subject</label>
                <input name="subject" id="subject">
            </div>

            <div class="b-form__inputWrap">
                <label for="name">Message</label>
                <textarea name="message" id="message" name="message" placeholder="enter message"></textarea>
            </div>

            <button class="b-form__btn" type="submit" name="submit">Send</button>
        </form>

PHP

         <?php
         error_reporting(E_ALL);
         ini_set('display_errors', 1); 

         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';

         if (isset($_POST["submit"])) {
         try {
         $mail = new PHPMailer(true);

         $mail->isSMTP();
         $mail->Host = 'smtp.gmail.com';
         $mail->SMTPAuth = true;
         $mail->Username = '$$$$$$$$$$';
         $mail->Password = '$$$$$$$$$$$$$$$$$'; 
         $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            
         $mail->Port = 465;   

    
         $mail->setFrom($_POST['email']);
         $mail->addAddress('$$$$$$$$$$$$$');
         $mail->addReplyTo($_POST['email']);
    
         $mail->isHTML(isHtml:true);

         $mail->Subject = $_POST["subject"];
         $mail->Body = $_POST["message"];

        $mail->send();
        echo 'Email sent successfully!';
       } catch (Exception $e) {
        echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
     }
    }


      ?>
php forms phpmailer
1个回答
-1
投票

您正在以 $$$$$$$$$$ 身份登录 Gmail。为什么他们会让您看起来像是从其他地址发送的?

这是一项安全措施。 Gmail 不会让你这样做。

© www.soinside.com 2019 - 2024. All rights reserved.