0

May I know why my sender and receiver are same email address.Seem I already set the setFrom with $email mean what I am typing in the input ,it will call to $email right?

enter image description here

PHP CODE 

<?php

require './PHPMailer/src/Exception.php';
require './PHPMailer/src/PHPMailer.php';
require './PHPMailer/src/SMTP.php';
use PHPMailer\PHPMailer\PHPMailer;

if (isset($_POST['send'])) {
    $name = htmlentities($_POST['name']);
    $email = htmlentities($_POST['email']);
    $subject = htmlentities($_POST['subject']);
    $message = htmlentities($_POST['message']);

    $mail = new PHPMailer(true);
    $mail->isSMTP();
    $mail->Host = 'smtp.gmail.com';
    $mail->SMTPAuth = true;
    $mail->Username = 'YOUR_EMAIL';
    $mail->Password = 'YOUR_PASSWORD';
    $mail->Port = 465;
    $mail->SMTPSecure = 'ssl';
    $mail->isHTML(true);
    $mail->setFrom($email, $name);
    $mail->addAddress('YOUR_RECEIVE_EMAIL');
    $mail->Subject = ($subject);
    $mail->Body = $message ;
    $mail->send();

    header("Location: ./response.html");
}`

HTML CODE

<form class="center_absolute display_grid" action="email.php" method="post">
    <input class="w_25_rem margin_bottom_1_rem" type="text" name="name" placeholder="Name" autocomplete="off">
    <input class="w_25_rem margin_bottom_1_rem" type="email" name="email" placeholder="Email" autocomplete="off">
    <input class="w_25_rem margin_bottom_1_rem" type="text" name="subject" placeholder="Subject" autocomplete="off">
    <textarea name="message" class="w_25_rem margin_bottom_1_rem" placeholder="Message..."></textarea>
    <div class="primary-checkbox-container margin_bottom_2_rem">
      <input class="primary-checkbox" type="checkbox" required>
      <div class="primary-checkbox-description color_black font_size_small">I agree to the <a class="font_size_small color_primary" href="https://rizalcss.com/privacy-policy" target="_blank">Privacy Policy</a>.</div>
    </div>
    <button class="primary-button background_color_primary font_size_medium color_white border_radius_secondary" type="submit" name="send">
      Send <i class="fa-solid fa-paper-plane primary-button-icon color_white"></i>
    </button>
  </form>
weikang Ng
  • 21
  • 2
  • Dose it happen everytime you submit the for ? I wonder if you have submitted your own email address in the form.. – Punit Gajjar Mar 14 '23 at 04:30
  • Yes, I type in the email input variable call $email – weikang Ng Mar 14 '23 at 06:06
  • 1
    Google doesn't let you pretend to be sending as a different account. You can specify what you want as the From address, they will overwrite it with the one of the account you authenticated for. – CBroe Mar 14 '23 at 07:21
  • "Faking" the sender is a bad idea to begin with, see https://stackoverflow.com/q/24644436/1427878, section titled "Don't use a faux From: sender". But the form user's email into Reply-To, then the receiver will be able to answer them directly via their mail client. – CBroe Mar 14 '23 at 07:22
  • [PHPMailer docs on this](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#dont-forge-from-addresses). – Synchro Mar 14 '23 at 08:25
  • The question does not match the code. Are you setting the $email in addAaddress as well ? – Rohit Gupta Mar 14 '23 at 13:20

0 Answers0