0

So, I have this PHP script on my website that sends a mail:

<?php
    $name= $_REQUEST['name'];
    $email = $_REQUEST['email'];
    $phone = $_REQUEST['phone'];
    $city = $_REQUEST['city'];
    $message = $_REQUEST['message'];
    $destination = "my@mail.com";
    $subject = "Contact Message";

    $header = "From: $email\r\n";
    $header .= "Return-Path: $email\r\n";

    $message2 = "Name: $name\r\n";
    $message2 .="Phone: $phone\r\n";
    $message2 .= "Email: $email\r\n";
    $message2 .= "City: $city\r\n";
    $message2 .= "Message: $message";

    mail($destination, $subject, $message2, $header);
    header('Location: thanks.php');
?>

and the HTML is:

<form method="post" action="mail.php">
    <p>Name</p>
    <input type="text" name="name" required>

    <p>Phone</p>
    <input type="tel" name="phone" required>

    <p>Email</p>
    <input type="email" name="email" required>

    <p>City</p>
    <input type="text" name="city" required>

    <p>Message</p>
    <textarea name="message" required></textarea>

    <button type="submit">SEND</button>

    <div class="clear"></div>
</form>

However the mail won't be sent if the mail is not my@mail.com (the same as my fixed destination). I don't why it happens, I have no clue at all. I've double checked every word to see if there's something wrong, but nothing. I've been using this script in multiple pages and it worked everytime.

nick
  • 2,819
  • 5
  • 33
  • 69
  • what are you setting `$destination` to when its not working? –  Sep 12 '16 at 21:17
  • destination is always the same, but in the contact form, if I put my@mail.com, it sends the mail but if I put my real mail e.g. personalmail@outlook.com it doesn't work, it's like the mail from the user has to be the same as the destination – nick Sep 12 '16 at 21:20
  • probably due to the fake (from) –  Sep 12 '16 at 21:21
  • but any real one doesn't work either, I tried with my personal email and it didn't work, however, it worked on the other websites I own – nick Sep 12 '16 at 21:22
  • the only non-fake from would be the one associated wit the account on the same server –  Sep 12 '16 at 21:28
  • But that form is intended for the users to comunicate with my client, it doesn't make sense that it has to be from the same server – nick Sep 12 '16 at 21:30
  • 1
    it makes complete sense to mailservers trying to prevent spam! –  Sep 12 '16 at 21:37

0 Answers0