PHP mail function sends to Gmail and Live but doesn't send to my own email

186 views Asked by At

I've got this script for a contact form that was working well on the old server. We needed to move on a new server and now it only works if I send emails to Gmail or Live address. If I try to send emails to my own email [email protected], it doesn't work.

    $from = trim($_POST['email']);
    $message = trim($_POST['message']);
    $username = trim($_POST['username']);

    /*Invia mail*/
    $body = '<html><body>';
    $body .= '<p><strong>Da:</strong> '.$username.' - '.$from.'</p>';
    $body .= '<p>'.$message.'</p>';
    $body .= '</body></html>';
    $headers = 'From: '.$from.'' . "\r\n";
    $headers .= 'MIME-Version: 1.0' . "\r\n" .
    'Content-type: text/html; charset=utf-8' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
    mail("[email protected]", "ActaPrivacy - Richiesta Assistenza", $body, $headers);

The php.ini file is exactly the same as the one from the old server. Server is linux and I left the default values

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = [email protected]

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = /usr/sbin/sendmail -t -i

I don't know what else I can do, what's weird is that it works if I send to Gmail, so why it doesn't work when I send to my own mail?

I can already move to PHPMailer, but I would also like to understand why this is not working properly if it was working before and the settings are the same.

1

There are 1 answers

1
Hirasawa Yui On BEST ANSWER

Do move to PHPMailer. Default php mail functions do not support modern security features. You can see that emails you received in gmail have a red padlock icon. Some of the mailboxes will never receive an unsecure email.